Advertisement
Guest User

Untitled

a guest
May 27th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from Crypto.Cipher import AES
  4. import sys
  5.  
  6. def split_len(seq, length):
  7. return [seq[i:i+length] for i in range(0, len(seq), length)]
  8.  
  9. def oracle(chosen):
  10. secret = "foobarbaz1234567890%sSecret42" % chosen # target to decrypt
  11. secret = getPadding(secret)
  12. if display:
  13. displaySecret(secret) # For illustrative purposes
  14. ct = cipher.encrypt(secret)
  15. return ct
  16.  
  17. def getPadding(secret):
  18. pl = len(secret)
  19. mod = pl % 16
  20. if mod != 0:
  21. padding = 16 - mod
  22. secret += "X" * padding
  23. return secret
  24.  
  25. def displaySecret(secret):
  26. split = split_len(secret, 16)
  27. display = ""
  28. for i in split:
  29. for j in split_len(i, 1):
  30. display += j + " "
  31. display += " "
  32.  
  33. print "pt: %s" % display
  34.  
  35. def displayCiphertext(ct):
  36. split = split_len(ct, 16)
  37. display = ""
  38.  
  39. for i in split:
  40. display += i.encode('hex') + " "
  41.  
  42. print "ct: %s" % (display)
  43.  
  44. if __name__ == "__main__":
  45. if len(sys.argv) < 2:
  46. exit("Usage: %s plaintext" % sys.argv[0])
  47.  
  48. display=True # Toggle for verbose out put
  49. key = "deadbeefcafecode"
  50. cipher = AES.new(key, AES.MODE_ECB, "\x00" * 16)
  51. cipher.block_size=8
  52.  
  53. chosen = sys.argv[1]
  54. ct = oracle(chosen)
  55. if display:
  56. displayCiphertext(ct)
  57. else:
  58. print ct.encode('hex')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement