Guest User

Untitled

a guest
Dec 12th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. require 'base64'
  2. require 'openssl'
  3.  
  4. bs = 192
  5. key_len = bs / 8
  6. iv_len = 16
  7.  
  8. plain = "ilovethisgameZz"
  9.  
  10. if ARGV.size == 2
  11. key = ARGV[0].split(' ').map { |i| Integer(i, 16) }.pack('C*')
  12. iv = ARGV[1].split(' ').map { |i| Integer(i, 16) }.pack('C*')
  13. else
  14. key = key_len.times.map { rand(256) }.pack('C*')
  15. iv = iv_len.times.map { rand(256) }.pack('C*')
  16. end
  17.  
  18. cipher = OpenSSL::Cipher::AES.new(bs, :CBC)
  19. cipher.encrypt
  20. # key = cipher.random_key
  21. # iv = cipher.random_iv
  22. cipher.key = key
  23. cipher.iv = iv
  24.  
  25. encrypted = cipher.update(plain) + cipher.final
  26. puts key.unpack('C*').map { |i| "%x" % i }.join(' ')
  27. puts iv.unpack('C*').map { |i| "%x" % i }.join(' ')
  28. puts Base64.encode64(encrypted)
Add Comment
Please, Sign In to add comment