def setUp(self): f = open('../../testdata/10.txt') self.ctxt = c1.base64toascii(f.read()) f.close() self.key = b'YELLOW SUBMARINE' self.iv = b'\x00' * 16 self.DEBUG = False
def encryption_oracle(): """ Encrypts a random string under AES-128-CBC Returns: A random, encrypted bytestring """ pt = random.choice(strs) pt = c1.base64toascii(pt) pt = c9.pkcs7_pad(pt) return c10.aes_128_cbc_encrypt(pt, key, iv)
def setUp(self): f = open('../../testdata/25.txt') self.ptxt = c1.base64toascii(f.read()) self.ptxt = c7.aes_128_ecb_decrypt(self.ptxt, b'YELLOW SUBMARINE') f.close()
def setUp(self): f = open('../../testdata/6.txt') self.ctxt = c1.base64toascii(f.read()) f.close()
def test_challenge_18(self): txt = b'L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syLXzhPweyyMTJULu/6/kXX0KSvoOLSFQ==' key = b'YELLOW SUBMARINE' pt = aes_128_ctr(c1.base64toascii(txt), key, 0) expected = b'Yo, VIP Let\'s kick it Ice, Ice, baby Ice, Ice, baby ' self.assertEqual(pt, expected)
def setUp(self): f = open('../../testdata/10.txt') self.ctxt = c1.base64toascii(f.read()) self.key = b'YELLOW SUBMARINE' self.pt = c10.aes_128_cbc_decrypt(self.ctxt, self.key) f.close()
def setUp(self): self.DEBUG = False f = open('../../testdata/7.txt') self.txt = c1.base64toascii(f.read()) f.close() self.key = b'YELLOW SUBMARINE'
def setUp(self): msg = b'VGhhdCdzIHdoeSBJIGZvdW5kIHlvdSBkb24ndCBwbGF5IGFyb' msg += b'3VuZCB3aXRoIHRoZSBGdW5reSBDb2xkIE1lZGluYQ==' self.msg = c1.base64toascii(msg)
5. Match the output of the one-byte-short input to one of the entries in your dictionary. You've now discovered the first byte of unknown-string. 6. Repeat for the next byte. """ import os, sys, unittest from Crypto.Cipher import AES sys.path.insert(0, '../set1') import c1, c6, c9 key = os.urandom(16) unknown = b'Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkg' unknown += b'aGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq' unknown += b'dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK' unknown = c1.base64toascii(unknown) # Encryption oracle def encryption_oracle(txt): """ Black box encryption oracle that appends an unknown string to the given text, pads it out, and encrypts under AES-128-ECB with an unknown key. Args: txt: The plaintext to be encrypted. Returns: AES-128-ECB(txt || unknown-string, random-key) as a bytestring """ return AES.new(key, AES.MODE_ECB).encrypt(c9.pkcs7_pad(txt + unknown))