ecb_cipher = AES.new(key, AES.MODE_ECB, iv)
ecb_ciphertexts = [ecb_cipher.encrypt(ca.pkcs7_pad(plaintext, AES.block_size))]
ecb_cipher = AES.new(key, AES.MODE_ECB, iv)
ecb_ciphertexts.append(ecb_cipher.encrypt(ca.pkcs7_pad(plaintext2,AES.block_size)))
print 'ECB ciphertexts are:'
print "\n".join([ct.encode('hex') for ct in ecb_ciphertexts])

cbc_cipher = AES.new(key, AES.MODE_CBC, iv)
cbc_ciphertexts = [cbc_cipher.encrypt(ca.pkcs7_pad(plaintext,AES.block_size))]
cbc_cipher = AES.new(key, AES.MODE_CBC, iv)
cbc_ciphertexts.append(cbc_cipher.encrypt(ca.pkcs7_pad(plaintext2,AES.block_size)))
print 'CBC fixed IV ciphertexts are:'
print "\n".join([ct.encode('hex') for ct in cbc_ciphertexts])

mb_xor_ciphertexts = [ca.sxor(plaintext,"\xfa\x4e\x77\x01\x43"*len(plaintext))]
mb_xor_ciphertexts.append(ca.sxor(plaintext2,"\xfa\x4e\x77\x01\x43"*len(plaintext2)))
print 'Multi-byte XOR ciphertexts are:'
print "\n".join([ct.encode('hex') for ct in mb_xor_ciphertexts])

two_time_pad_ciphertexts = [ca.sxor(plaintext,two_time_pad_key)]
two_time_pad_ciphertexts.append(ca.sxor(plaintext2,two_time_pad_key))
print 'Two-time pad ciphertexts are:'
print "\n".join([ct.encode('hex') for ct in two_time_pad_ciphertexts])

compressed_messages = [compress(plaintext), compress(plaintext2)]

print 'Analyzing ECB ciphertexts...'
ca.analyze_ciphertext(ecb_ciphertexts,verbose=True)
print ''
print 'Analyzing CBC fixed-IV ciphertexts...'
'Who run Barter Town? Master Blaster!',
'Damon brings in tacos from Taco Hut',
'He was an analyst, he brought tacos',
'I am looking for Skyrim employment',
'You might say I\'m looking for Skyrim work',
'Almost as if I\'m seeking a Skyrim trade',
'You could say I want a Skyrim labor agreement',
'I used to be an adventurer like you',
'Until I took an arrow to the knee',
'Okay, the joke is Skyrim job, it\'s funny'
'Can I stop writing out plaintexts now',
'Charles Dickens is a big windbag',
'I can only come up with so much random',
'stuff and then I have to ask for help',
'from Will, who just repeats my words',
'My brain is melting, as is my waaaaaaaaang',
'I really need more sleep than I get',
'Sleep is for the weak, Skub is for the strong',
'F**k those anti-skub losers, skub is the best'
]

ciphertexts = []

for plaintext in plaintexts:
   ciphertexts.append(ca.sxor(key, plaintext))

print 'Testing many-time pad solver...'
print ca.break_many_time_pad(ciphertexts, verbose=True)
if raw_input('Did this decrypt correctly (yes)?').lower() not in ['y','yes','']:
   raise Exception('Many time pad solver failed.')
import cryptanalib as ca

plaintext = 'I am the very model of a modern major-general'

ciphertext = ca.sxor(plaintext, '\x3f'*len(plaintext))
output = ca.break_single_byte_xor(ciphertext)
print output
if output[0][0] != plaintext:
   raise Exception('Single byte XOR solver is broken')
Exemplo n.º 4
0
import cryptanalib as ca

plaintext = 'I am the very model of a modern major-general'

ciphertext = ca.sxor(plaintext, '\x3f' * len(plaintext))
output = ca.break_single_byte_xor(ciphertext)
print output
if output[0][0] != plaintext:
    raise Exception('Single byte XOR solver is broken')