#!/usr/bin/env python
from Crypto.Cipher import AES
import base64
import os
# the block size for the cipher object; must be 16, 24, or 32 for AES
BLOCK_SIZE = 32
# the character used for padding--with a block cipher such as AES, the value
# you encrypt must be a multiple of BLOCK_SIZE in length. This character is
# used to ensure that your value is always a multiple of BLOCK_SIZE
PADDING = '{'
# one-liner to sufficiently pad the text to be encrypted
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
# one-liners to encrypt/encode and decrypt/decode a string
# encrypt with AES, encode with base64
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
# generate a random secret key
secret = os.urandom(BLOCK_SIZE)
# create a cipher object using the random secret
cipher = AES.new(secret)
# encode a string
encoded = EncodeAES(cipher, 'password')
print 'Encrypted string:', encoded
# decode the encoded string
decoded = DecodeAES(cipher, encoded)
print 'Decrypted string:', decoded
# your code goes here
IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCgpmcm9tIENyeXB0by5DaXBoZXIgaW1wb3J0IEFFUwppbXBvcnQgYmFzZTY0CmltcG9ydCBvcwoKIyB0aGUgYmxvY2sgc2l6ZSBmb3IgdGhlIGNpcGhlciBvYmplY3Q7IG11c3QgYmUgMTYsIDI0LCBvciAzMiBmb3IgQUVTCkJMT0NLX1NJWkUgPSAzMgoKIyB0aGUgY2hhcmFjdGVyIHVzZWQgZm9yIHBhZGRpbmctLXdpdGggYSBibG9jayBjaXBoZXIgc3VjaCBhcyBBRVMsIHRoZSB2YWx1ZQojIHlvdSBlbmNyeXB0IG11c3QgYmUgYSBtdWx0aXBsZSBvZiBCTE9DS19TSVpFIGluIGxlbmd0aC4gIFRoaXMgY2hhcmFjdGVyIGlzCiMgdXNlZCB0byBlbnN1cmUgdGhhdCB5b3VyIHZhbHVlIGlzIGFsd2F5cyBhIG11bHRpcGxlIG9mIEJMT0NLX1NJWkUKUEFERElORyA9ICd7JwoKIyBvbmUtbGlu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