Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Rsa
- def createKeys(p, q, e)
- d = 1
- n = p * q;
- eiler = ((p-1) * (q - 1));
- while (d % e != 0)
- d += eiler;
- end
- d = d / e;
- hash_key = {"public" => [e, n], "private" => [d, n]}
- end
- def rsa_crypt(md5, hash)
- @code = ''
- md5.each_byte { |c| @code += (c**hash["public"][0] % hash["public"][1]).to_s }
- end
- def rsa_decrypt(md5, hash)
- @code = ''
- md5.each_byte { |c| @code += (c**hash["private"][0] % hash["private"][1]).to_s }
- end
- def crypt
- hash = createKeys(47,71,3)
- puts "hash: #{hash.each { |element| element }}"
- crypt = rsa_crypt("69380a4489890f8a53e0eddc36cd1379",hash)
- puts "crypt: #{crypt}"
- decrypt = rsa_decrypt(crypt ,hash)
- puts "decrypt: #{decrypt}"
- end
- end
- m = Rsa.new
- m.crypt
Add Comment
Please, Sign In to add comment