To unserdatand the cipher naming (eg. AES-128-CBC), it devided to 3 parts seperated by hyphen <Name>-<Key_length>-<Mode>
Symmetric encrption algorithms modes need 3 import data in order to work
Key (password)
Initial Vector (iv)
Data to encrypt (plain text)
AES encryption
Encrypt
require"openssl"data ='Rubyfu Secret Mission: Go Hack The World!'# Setup the ciphercipher =OpenSSL::Cipher::AES.new('256-CBC') # Or use: OpenSSL::Cipher.new('AES-256-CBC')cipher.encrypt # Initializes the Cipher for encryption. (Must be called before key, iv, random_key, random_iv)
key = cipher.random_key # If hard coded key, it must be 265-bits lengthiv = cipher.random_iv # Generate ivencrypted = cipher.update(data) + cipher.final # Finalize the encryption
Dencrypt
decipher =OpenSSL::Cipher::AES.new('256-CBC') # Or use: OpenSSL::Cipher::Cipher.new('AES-256-CBC')decipher.decrypt # Initializes the Cipher for dencryption. (Must be called before key, iv, random_key, random_iv)
decipher.key = key # Or generate secure random key: cipher.random_keydecipher.iv = iv # Generate ivplain = decipher.update(encrypted) + decipher.final # Finalize the dencryption
Caesar cipher is one of the oldest known encryption methods. It is very simple - it is just shifting an alphabet. Transformation is termed ROTN, where N is shift value and ROT is from "ROTATE" because this is a cyclic shift.
In Ruby, array rotation is mutter of using rotate() method. So all what we need is to have array of all alphabets rotate it and map it with the original given string.