Today's public key is { :n => 46, :e => 5 }
def rsa_encrypt(message, public_key)
n = public_key[:n]
e = public_key[:e]
n_arr = message.downcase.scan(/[a-z]| /).map { |character|
"abcdefghijklmnopqrstuvwxyz ".index(character)
}
n_arr.map { |m|
(m ** e).modulo n
}
end
def rsa_decrypt(ciphertext, private_key)
n = private_key[:n]
d = private_key[:d]
n_arr = ciphertext.map { |c|
(c ** d).modulo n
}
n_arr.map { |n| "abcdefghijklmnopqrstuvwxyz "[n,1] }.join('')
end
And the secret message is: [11, 38, 13, 0, 24, 36, 16, 26, 36, 18, 24, 36, 1, 16, 21, 11, 17, 13, 0, 24]