def testChallenge10(self): input = fromAscii('YELLOW SUBMARINEYELLOW SUBMARINE') key = b'YELLOW SUBMARINE' self.assertEqual(decryptAESCBC(encryptAESCBC(input, key), key), input) with open('resources/set2-challenge10.txt', 'r') as testDataFile: input = fromB64(testDataFile.read().replace('\n', '')) self.assertIn(b'Let the witch doctor, Ice, do the dance to cure ', decryptAESCBC(input, key))
def encryptAESECBWithFixedPrefixSuffix(data, key=None, suffix=None, prefix=None): # Default suffix comes from challenge 12 suffix = fromB64('Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK') if suffix == None else suffix prefix = fromAscii('Thats our fixed-length prefix') if prefix == None else prefix key = UNKNOWN_AES_KEY if key == None else key return AES.new(key).encrypt(pkcs7Padding(prefix+data+suffix))
def testChallenge9(self): input = fromAscii('YELLOW SUBMARINE') output = fromAscii('YELLOW SUBMARINE\x04\x04\x04\x04') self.assertEqual(pkcs7Padding(input, 20), output)
def encryptUserProfile(email): return AES.new(UNKNOWN_AES_KEY).encrypt(pkcs7Padding(fromAscii(profileFor(email))))