#!/usr/bin/env python3.6 import cryptopals finalKey = None finalScr = 0.0 finalOut = '' with open('4.txt') as inFile: fileLines = inFile.read().split('\n') for l in fileLines: xorKey, xorScr, xorOut = cryptopals.findXorKey(bytes.fromhex(l)) if xorScr > finalScr: finalKey = xorKey finalScr = xorScr finalOut = xorOut finalOut = finalOut.decode('utf-8').strip() # stringify print('KEY: %s' % (finalKey,)) print('SCR: %s' % (finalScr,)) print('XOR: %s' % (finalOut,), end=' ') cryptopals.test(finalOut, "Now that the party is jumping")
#!/usr/bin/env python3.6 import cryptopals input1 = "Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal".encode('utf-8') key = 'ICE'.encode('UTF-8') output1 = cryptopals.repeatingXor(input1, key).hex() output2 = cryptopals.repeatingXor(bytes.fromhex(output1), key) print('INP: %s' % (input1,)) print('KEY: %s' % (key,)) print('OUT: %s' % (output1,), end=' ') cryptopals.test(output1, '0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f') print('OUT: %s' % (output2,), end=' ') cryptopals.test(output2, input1)
#!/usr/bin/env python3 import cryptopals key = b'YELLOW SUBMARINE' initial = cryptopals.pcksPad(b'Loki the cat') blockSize = 16 iv = bytes([0] * blockSize) encryptedECB = cryptopals.encryptAESDataECB(initial, key) encryptedCBC = cryptopals.encryptAESDataCBC(initial, key, iv) decryptedECB = cryptopals.decryptAESDataECB(encryptedECB, key) decryptedCBC = cryptopals.decryptAESDataCBC(encryptedCBC, key, iv) print('Initial = %s' % (initial, )) print('Encrypted ECB = %s' % (encryptedECB, )) print('Encrypted CBC = %s' % (encryptedCBC, ), end=' ') cryptopals.test(encryptedECB, encryptedCBC) print('Decrypted ECB = %s' % (decryptedECB, ), end=' ') cryptopals.test(decryptedECB, initial) print('Decrypted CBC = %s' % (decryptedCBC, ), end=' ') cryptopals.test(decryptedCBC, initial) cipherdata = cryptopals.loadBase64File('10.txt') plaindata = cryptopals.decryptAESDataCBC(cipherdata, key, iv) print('plaindata = %s' % (plaindata.decode('utf-8'), ))
#!/usr/bin/env python3 import cryptopals initial = b'YELLOW SUBMARINE' # 16 bytes expected = b'YELLOW SUBMARINE\x04\x04\x04\x04' # 20 bytes print('Initial = %s' % (initial, )) print('Expected = %s' % (expected, ), end=' ') cryptopals.test(cryptopals.pcksPad(initial, 20), expected)
#!/usr/bin/env python3.6 import cryptopals input1 = '1c0111001f010100061a024b53535009181c' input2 = '686974207468652062756c6c277320657965' xorOut = cryptopals.xorHexStrings(input1, input2) print('IN1: %s' % (input1, )) print('IN2: %s' % (input2, )) print('XOR: %s' % (xorOut, ), end=' ') cryptopals.test(xorOut, '746865206b696420646f6e277420706c6179')
#!/usr/bin/env python3 import cryptopals input1 = "this is a test".encode('utf-8') input2 = "wokka wokka!!!".encode('utf-8') distance = cryptopals.getHammingDistance(input1, input2) print('IN1: %s' % (input1,)) print('IN2: %s' % (input2,)) print('OUT: %d' % (distance,), end=' ') cryptopals.test(distance, 37) cipherdata = cryptopals.loadBase64File('6.txt') foundKey = cryptopals.breakRepeatingKeyXor(cipherdata) print('KEY: %s' % (foundKey.decode('utf-8'),)) print('DEC: %s' % (cryptopals.repeatingXor(cipherdata, foundKey).decode('utf-8'),))