Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. from Crypto.Cipher import AES
  2. import os
  3. from binascii import hexlify
  4.  
  5. BLOCK_SIZE = 16
  6. def pad(raw):
  7.     if len(raw) % 16>0:
  8.         return raw + bytes(16-(len(raw)%16))
  9.     return raw
  10.  
  11. def aes_enc(key, msg):
  12.     cipher = AES.new(key, AES.MODE_ECB)
  13.     return cipher.encrypt(msg)
  14.  
  15. secret_key = os.urandom(32) # 32 bytes secret (AES-256)
  16. print('Secret KEY='+str(hexlify(secret_key).upper()))
  17.  
  18. f = open('BLK.BMP','rb')
  19. plain_text = f.read()
  20. f.close()
  21. print('plain_text bytes='+str(len(plain_text)))
  22. plain_text_padded = pad(plain_text) # Padding plain text to 16 block size
  23. print('plain_text_padded bytes='+str(len(plain_text_padded)))
  24.  
  25. cypher_text = aes_enc(secret_key, plain_text_padded)
  26. print(hexlify(cypher_text))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement