Exemplo n.º 1
0
 def testXorBuffers(self):
     self.assertEqual(
             "746865206b696420646f6e277420706c6179", 
         hex_encode(xor_fixed_length_buffers(
             hex_decode("1c0111001f010100061a024b53535009181c")[0],
             hex_decode("686974207468652062756c6c277320657965")[0]
         ))[0]
     )
Exemplo n.º 2
0
    def testDetectSingleByteXorCipher(self):
        with open("4.txt", "rb") as file_handle:
            results = {}
            for ciphertext_encoded in file_handle:
                ciphertext = hex_decode(ciphertext_encoded.rstrip())[0]
                key_guess = find_single_byte_cipher_key(ciphertext)
                plaintext = xor_fixed_length_buffers(ciphertext, key_guess*len(ciphertext))
                score = english_score(plaintext)

                results[plaintext] = { "score" : score, "key" : key_guess }

            sorted_list = sorted(results, key=lambda(k): results[k]["score"], reverse=True)

            self.assertEqual("Now that the party is jumping\n", sorted_list[0])
Exemplo n.º 3
0
def hexstring_to_b64(hex_string):
    binary_string = hex_decode(hex_string)[0]
    return b64encode(binary_string)
Exemplo n.º 4
0
    def testSingleByteXorDecryption(self):
        ciphertext = hex_decode("1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736")[0]
        guess = find_single_byte_cipher_key(ciphertext)
        plaintext = xor_fixed_length_buffers(ciphertext, guess*len(ciphertext)) 

        self.assertEqual("Cooking MC's like a pound of bacon", plaintext)