<commit_before>import string
import unittest

import stringlib


def solve(plaintext, key):
    plainbytes = stringlib.encode_hex(bytes(plaintext, encoding='ascii'))
    ltext, lkey = len(plaintext), len(key)
    reps = (ltext + lkey - 1) // lkey
    rep_key = key * reps
    keybytes = stringlib.encode_hex(bytes(rep_key, encoding='ascii'))
    return stringlib.xor_hexes(plainbytes, keybytes)


class Test(unittest.TestCase):
    def test_solve(self):
        key = "ICE"
        plaintext = "Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal"
        ciphertext = b"0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f"
        self.assertEqual(solve(plaintext, key), ciphertext)<commit_msg>Test1.5: XOR strings using pycrypto.<commit_after>import string
import unittest

from Crypto.Util import strxor

import stringlib


def solve(plaintext, key):
    ltext, lkey = len(plaintext), len(key)
    reps = (ltext + lkey - 1) // lkey
    rep_key = (key * reps)[:ltext]
    ciphertext = strxor.strxor(plaintext, rep_key)
    return stringlib.encode_hex(ciphertext).lower()


class Test(unittest.TestCase):
    def test_solve(self):
        key = b"ICE"
        plaintext = b"Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal"
        ciphertext = b"<KEY>"
        self.assertEqual(solve(plaintext, key), ciphertext)
{'fraction_non_alphanumeric': 0.09986320109439124, 'fraction_numerical': 0.08481532147742818, 'mean_word_length': 4.079861111111111, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2429656', 'n_tokens_mistral': 610, 'n_tokens_neox': 516, 'n_words': 117}