def encrypt_random_choice(key): selection = secret_messages[random.randint(0, len(secret_messages) - 1)] init_vector = iv() return ( cbc_encrypt(selection, key, init_vector), init_vector, )
def encrypt_kvps(content, key, iv): full_content = ( 'comment1=cooking%20MCs;userdata=' + urllib.quote(content) + ';comment2=%20like%20a%20pound%20of%20bacon' ) return cbc_encrypt(full_content, key, iv)
def test_challenge10(self): ciphertext = base64_to_bytes(read('10.txt')) key = 'YELLOW SUBMARINE' iv = '\x00' * 16 plaintext = cbc_decrypt(ciphertext, key, iv) ciphertext = cbc_encrypt(plaintext, key, iv) plaintext2 = cbc_decrypt(ciphertext, key, iv) self.assertEquals(plaintext, plaintext2)
def multimode_oracle(plaintext, mode): tampered = random_padding() + plaintext + random_padding() key = encryption_key() if mode == 'ecb': return ecb_encrypt(tampered, key) elif mode == 'cbc': return cbc_encrypt(tampered, key, iv()) raise ValueError('Unknown mode')
def echo(self, message): s = pow(self.A, self.b, self.p) key = Sha1Hash().update(to_bytes_le(s)).digest()[:16] ciphertext = message[:-16] iv = message[-16:] plaintext = crypto.cbc_decrypt(ciphertext, key, iv) self.messages.append(plaintext) iv = crypto.iv() return crypto.cbc_encrypt(plaintext, key, iv) + iv
def send(self, receiver, message): self.messages.append(message) B = receiver.handshake(self.p, self.g, self.A) s = pow(B, self.a, self.p) key = Sha1Hash().update(to_bytes_le(s)).digest()[:16] iv = crypto.iv() ciphertext = crypto.cbc_encrypt(message, key, iv) + iv returned_message = receiver.echo(ciphertext) returned_ciphertext = returned_message[:-16] returned_iv = returned_message[-16:] decrypted = crypto.cbc_decrypt( returned_ciphertext, key, returned_iv ) return decrypted
def GET(self): msg = crypto.cbc_encrypt(secret, master_key).encode("hex") return render.generic(form.Form(),"You eavesdropped the following message:",msg,False)
def encrypt_url(content, key): return crypto.cbc_encrypt(full_content, key, key)