예제 #1
0
	def setUpClass(cls):
		cls.encoder = encode_xor.XOREncoder()
예제 #2
0
파일: ch06.py 프로젝트: yvshri/matasano
                  key=lambda x: keysizes_with_distance[x])


def breakXOR(text, min_keysize, max_keysize):
    bin_text = enclib.Base64ToBin(text)

    keysizes = sortKeysizes(bin_text, min_keysize, max_keysize)
    print('[**] Keysizes: ', str(keysizes))

    for keysize in keysizes[:5]:
        key = findKey(bin_text, keysize)

        if key:
            return key

    return ''


if __name__ == "__main__":
    encrypted_text = ''
    with open('data/6.txt', 'r') as f:
        encrypted_text = f.read()

    key = breakXOR(encrypted_text, 2, 40)
    if key:
        print('[**] Key found: ' + key)
        print('*** DECRYPTED MESSAGE ***')

        encoder = encode_xor.XOREncoder()
        print(encoder.EncodeAsAscii(enclib.Base64ToAscii(encrypted_text), key))