Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Crypto.Cipher import AES
- import base64
- import os
- def encryption(privateInfo):
- BLOCK_SIZE = 16
- PADDING = '{'
- pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
- EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
- secret = os.urandom(BLOCK_SIZE)
- secret = bytes(secret)
- cipher = AES.new(secret)
- encoded = EncodeAES(cipher, privateInfo)
- respuesta = [secret, encoded] # key y mensaje cifrado
- return respuesta
- def decryption(encryptedString, key):
- PADDING = '{'
- DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
- encryption = encryptedString
- cipher = AES.new(key)
- decoded = DecodeAES(cipher, encryption)
- return decoded
- def main():
- mensaje = raw_input("Ingrese su mensaje: ")
- respuesta = encryption(mensaje)
- print respuesta[1] # mensaje cifrado
- print respuesta[0] # key
- print decryption(respuesta[1], respuesta[0])
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement