require 'openssl' ALGORITHM = 'AES-256-CBC' puts 'Enter message to encrypt:' message = gets.chomp cipher = OpenSSL::Cipher.new(ALGORITHM) key = cipher.random_key hex_key = key.unpack('H*').first puts "Randomly generated key in hexadecimal: #{hex_key}" cipher.encrypt cipher.key = key encrypted_message = cipher.update(message) encrypted_message << cipher.final hex_encrypted_message = encrypted_message.unpack('H*').first puts "Encrypted message in hexadecimal: #{hex_encrypted_message}"