def encrypt_decrypt_CTR(text, key, nonce): le_nonce = int_to_little_endian(nonce, 8) keystream = '' for i in range(len(text) / 16 + 1): val = le_nonce + int_to_little_endian(i, 8) keystream += chal7.encrypt_ECB(val, key) return chal10.xor_data(text, keystream[:len(text)])
def encrypt_CBC(plaintext, key, iv): ciphertext = '' last_cipher = iv plaintext = chal9.pad(plaintext, 16) for i in range(len(plaintext) / BLOCK_SIZE): plain_block = plaintext[i * BLOCK_SIZE:(i + 1) * BLOCK_SIZE] plain_block = xor_data(plain_block, last_cipher) last_cipher = chal7.encrypt_ECB(plain_block, key) ciphertext += last_cipher return ciphertext
def encryption_oracle(plaintext): aes_key = get_random_bytes(16) plaintext = get_random_bytes(random.randint( 5, 10)) + plaintext + get_random_bytes(random.randint(5, 10)) ecb_flag = (0 == random.randint(0, 1)) #print ecb_flag if ecb_flag: #ecb encryption plaintext = chal9.pad(plaintext, 16) return chal7.encrypt_ECB(plaintext, aes_key) else: iv = get_random_bytes(16) return chal10.encrypt_CBC(plaintext, aes_key, iv)
def encryption_oracle(plaintext): plaintext = plaintext+base64.b64decode(unknown_string) plaintext = chal9.pad(plaintext,16) return chal7.encrypt_ECB(plaintext,KEY)
def encrypt(plaintext, key): plaintext = chal9.pad(plaintext, 16) return chal7.encrypt_ECB(plaintext, key)