Exemplo n.º 1
0
    def test_xor_key_same_length(self):
        hex1 = "1c0111001f010100061a024b53535009181c"
        hex2 = "686974207468652062756c6c277320657965"
        target = "746865206b696420646f6e277420706c6179"

        self.assertEqual(
            HexEncoder.encode(
                Xor.encrypt(HexEncoder.decode(hex1), HexEncoder.decode(hex2))),
            target)
Exemplo n.º 2
0
    def test_repeating_key_xor(self):
        plaintext = "Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal"
        key = "ICE"
        target = "0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f"

        self.assertEqual(HexEncoder.encode(Xor.encrypt(key, plaintext)),
                         target)
Exemplo n.º 3
0
    def test_estimate_plaintext_and_key(self):
        source = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"
        target = ("Cooking MC's like a pound of bacon", "X")

        self.assertEqual(
            self.estimator.estimate_plaintext_key_pair(
                HexEncoder.decode(source)), target)
    def test_detect_single_char_xor(self):
        with open(f"{self._get_fixtures_path()}/single_char_xor.txt",
                  "r") as file:
            estimate = lambda line: self.estimator.estimate_plaintext_key_pair(
                HexEncoder.decode(line.strip()))
            estimated_plaintext_key_pairs = {
                estimate(line): self.estimator.score_text(estimate(line)[0])
                for line in file
            }

            self.assertEqual(
                max(estimated_plaintext_key_pairs,
                    key=estimated_plaintext_key_pairs.get),
                ('Now that the party is jumping\n', '5'))
Exemplo n.º 5
0
 def test_detect_aes_ecb(self):
     with open(os.path.join(get_fixtures_path(), "detect_aes_ecb.txt"), "r") as file:
         lines = file.readlines()
         aes_ecb_detected = lambda line: self.aes_ecb_estimator.is_aes_ecb_encrypted(HexEncoder.decode(line.strip()))
         lines_aes_detected_dict = {
             line.strip(): aes_ecb_detected(line)
             for line in lines if aes_ecb_detected(line)
         }
         
         target = {"d880619740a8a19b7840a8a31c810a3d08649af70dc06f4fd5d2d69c744cd283e2dd052f6b641dbf9d11b0348542bb5708649af70dc06f4fd5d2d69c744cd2839475c9dfdbc1d46597949d9c7e82bf5a08649af70dc06f4fd5d2d69c744cd28397a93eab8d6aecd566489154789a6b0308649af70dc06f4fd5d2d69c744cd283d403180c98c8f6db1f2a3f9c4040deb0ab51b29933f2c123c58386b06fba186a": True}
         self.assertEqual(target, lines_aes_detected_dict)
Exemplo n.º 6
0
    def test_encode(self):
        source = "I'm killing your brain like a poisonous mushroom"
        target = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"

        self.assertEqual(HexEncoder.encode(source), target)