import set1 a = set1.strToHex('1c0111001f010100061a024b53535009181c') b = set1.strToHex('686974207468652062756c6c277320657965') result = set1.bufferXOR(a,b) print ''.join(format(x, '02x') for x in result)
import set1 input = set1.strToHex('1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736') print set1.breakSingleCharXOR(input)
import set1 import string lines = (line.rstrip('\n') for line in open('4.txt')) best = [] for line in lines: best.append(set1.breakSingleCharXOR(set1.strToHex(line))) print sorted(best)[-1]
from Crypto.Cipher import AES import array import set1 import sys import string lines = (set1.strToHex(line.rstrip('\n')) for line in open('8.txt')) counted = [] for line in lines: count = set1.twoByteMatch(line) counted.append((count, ''.join(format(x, '02x') for x in line))) print sorted(counted)[-1]
import sys import array import set1 def hammingDistance(a, b): if len(a) != len(b): print "hammingDistance: lengths aren't equal" sum = 0 for byteA, byteB in zip(a,b): sum += bin(byteA ^ byteB).count('1') return sum fileContents = open(sys.argv[1] , "rb").read() input = set1.strToHex(fileContents) guesses = [] for keyLenGuess in range (1, 40): block1 = input[ : keyLenGuess+1] block2 = input[keyLenGuess : (2 * keyLenGuess)+1] block3 = input[(2 * keyLenGuess) : (3 * keyLenGuess)+1] block4 = input[(3 * keyLenGuess) : (4 * keyLenGuess)+1] distanceNorm = (hammingDistance(block1, block2) + hammingDistance(block3, block4) + hammingDistance(block1, block3) + hammingDistance(block4, block1)) / (keyLenGuess * 4.) guesses.append((distanceNorm, keyLenGuess)) # print sorted(guesses) guess = sorted(guesses)[0][1] lenGuesses = [x[1] for x in sorted(guesses)[:3]] byteWiseBlocks = [[] for x in range(0, guess)]
from Crypto.Cipher import AES import array import set1 import sys import string fileBytes = array.array('B', set1.strToHex(open(sys.argv[1] , "rb").read())) cipherObj = AES.new('YELLOW SUBMARINE', AES.MODE_ECB) cipherText = cipherObj.decrypt(fileBytes) print cipherText
import set1 input = set1.strToHex( '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736') print set1.breakSingleCharXOR(input)
import set1 a = set1.strToHex('1c0111001f010100061a024b53535009181c') b = set1.strToHex('686974207468652062756c6c277320657965') result = set1.bufferXOR(a, b) print ''.join(format(x, '02x') for x in result)
import set1 def hammingDistance(a, b): if len(a) != len(b): print "hammingDistance: lengths aren't equal" sum = 0 for byteA, byteB in zip(a, b): sum += bin(byteA ^ byteB).count('1') return sum fileContents = open(sys.argv[1], "rb").read() input = set1.strToHex(fileContents) guesses = [] for keyLenGuess in range(1, 40): block1 = input[:keyLenGuess + 1] block2 = input[keyLenGuess:(2 * keyLenGuess) + 1] block3 = input[(2 * keyLenGuess):(3 * keyLenGuess) + 1] block4 = input[(3 * keyLenGuess):(4 * keyLenGuess) + 1] distanceNorm = (hammingDistance(block1, block2) + hammingDistance( block3, block4) + hammingDistance(block1, block3) + hammingDistance(block4, block1)) / (keyLenGuess * 4.) guesses.append((distanceNorm, keyLenGuess)) # print sorted(guesses) guess = sorted(guesses)[0][1] lenGuesses = [x[1] for x in sorted(guesses)[:3]]