Guest User

Untitled

a guest
Jun 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. class Rsa
  2. def createKeys(p, q, e)
  3. d = 1
  4. n = p * q;
  5. eiler = ((p-1) * (q - 1));
  6.  
  7. while (d % e != 0)
  8. d += eiler;
  9. end
  10. d = d / e;
  11.  
  12. hash_key = {"public" => [e, n], "private" => [d, n]}
  13. end
  14.  
  15. def rsa_crypt(md5, hash)
  16. @code = ''
  17. md5.each_byte { |c| @code += (c**hash["public"][0] % hash["public"][1]).to_s }
  18. end
  19.  
  20. def rsa_decrypt(md5, hash)
  21. @code = ''
  22. md5.each_byte { |c| @code += (c**hash["private"][0] % hash["private"][1]).to_s }
  23. end
  24.  
  25. def crypt
  26. hash = createKeys(47,71,3)
  27. puts "hash: #{hash.each { |element| element }}"
  28. crypt = rsa_crypt("69380a4489890f8a53e0eddc36cd1379",hash)
  29. puts "crypt: #{crypt}"
  30. decrypt = rsa_decrypt(crypt ,hash)
  31. puts "decrypt: #{decrypt}"
  32. end
  33. end
  34.  
  35. m = Rsa.new
  36. m.crypt
Add Comment
Please, Sign In to add comment