<commit_before>import textwrap

from .utils import load_nist_vectors, load_nist_vectors_from_file


def test_load_nist_vectors_encrypt():
    vector_data = textwrap.dedent("""
    # CAVS 11.1
    # Config info for aes_values
    # AESVS GFSbox test data for CBC
    # State : Encrypt and Decrypt
    # Key Length : 128
    # Generated on Fri Apr 22 15:11:33 2011

    [ENCRYPT]

    COUNT = 0
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6
    CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e

    COUNT = 1
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    PLAINTEXT = 9798c4640bad75c7c3227db910174e72
    CIPHERTEXT = a9a1631bf4996954ebc093957b234589

    [DECRYPT]

    COUNT = 0
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e
    PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6

    COUNT = 1
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    CIPHERTEXT = a9a1631bf4996954ebc093957b234589
    PLAINTEXT = 9798c4640bad75c7c3227db910174e72
    """).splitlines()

    assert load_nist_vectors(vector_data, "ENCRYPT",
        ["key", "iv", "plaintext", "ciphertext"],
    ) == [
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"f34481ec3cc627bacd5dc3fb08f273e6",
            b"0336763e966d92595a567cc9ce537f5e",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"9798c4640bad75c7c3227db910174e72",
            b"a9a1631bf4996954ebc093957b234589",
        ),
    ]


def test_load_nist_vectors_decrypt():
    vector_data = textwrap.dedent("""
    # CAVS 11.1
    # Config info for aes_values
    # AESVS GFSbox test data for CBC
    # State : Encrypt and Decrypt
    # Key Length : 128
    # Generated on Fri Apr 22 15:11:33 2011

    [ENCRYPT]

    COUNT = 0
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6
    CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e

    COUNT = 1
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    PLAINTEXT = 9798c4640bad75c7c3227db910174e72
    CIPHERTEXT = a9a1631bf4996954ebc093957b234589

    [DECRYPT]

    COUNT = 0
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e
    PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6

    COUNT = 1
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    CIPHERTEXT = a9a1631bf4996954ebc093957b234589
    PLAINTEXT = 9798c4640bad75c7c3227db910174e72
    """).splitlines()

    assert load_nist_vectors(vector_data, "DECRYPT",
        ["key", "iv", "ciphertext", "plaintext"],
    ) == [
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"0336763e966d92595a567cc9ce537f5e",
            b"<KEY>",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"<KEY>",
            b"9798c4640bad75c7c3227db910174e72",
        ),
    ]


def test_load_nist_vectors_from_file_encrypt():
    assert load_nist_vectors_from_file(
        "AES/KAT/CBCGFSbox256.rsp",
        "ENCRYPT",
        ["key", "iv", "plaintext", "ciphertext"],
    ) == [
        (
            b"0000000000000000000000000000000000000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"014730f80ac625fe84f026c60bfd547d",
            b"5c9d844ed46f9885085e5d6a4f94c7d7",
        ),
        (
            b"0000000000000000000000000000000000000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"0b24af36193ce4665f2825d7b4749c98",
            b"a9ff75bd7cf6613d3731c77c3b6d0c04",
        ),
        (
            b"0000000000000000000000000000000000000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"761c1fe41a18acf20d241650611d90f1",
            b"623a52fcea5d443e48d9181ab32c7421",
        ),
        (
            b"0000000000000000000000000000000000000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"8a560769d605868ad80d819bdba03771",
            b"38f2c7ae10612415d27ca190d27da8b4",
        ),
        (
            b"0000000000000000000000000000000000000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"91fbef2d15a97816060bee1feaa49afe",
            b"1bc704f1bce135ceb810341b216d7abe",
        ),
    ]


def test_load_nist_vectors_from_file_decypt():
    assert load_nist_vectors_from_file(
        "AES/KAT/CBCGFSbox256.rsp",
        "DECRYPT",
        ["key", "iv", "ciphertext", "plaintext"],
    ) == [
        (
            b"0000000000000000000000000000000000000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"5c9d844ed46f9885085e5d6a4f94c7d7",
            b"014730f80ac625fe84f026c60bfd547d",
        ),
        (
            b"0000000000000000000000000000000000000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"a9ff75bd7cf6613d3731c77c3b6d0c04",
            b"0b24af36193ce4665f2825d7b4749c98",
        ),
        (
            b"0000000000000000000000000000000000000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"623a52fcea5d443e48d9181ab32c7421",
            b"761c1fe41a18acf20d241650611d90f1",
        ),
        (
            b"0000000000000000000000000000000000000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"38f2c7ae10612415d27ca190d27da8b4",
            b"8a560769d605868ad80d819bdba03771",
        ),
        (
            b"0000000000000000000000000000000000000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"1bc704f1bce135ceb810341b216d7abe",
            b"91fbef2d15a97816060bee1feaa49afe",
        ),
    ]<commit_msg>Use a test file with shorter keys so that all lines match our coding standard<commit_after>import textwrap

from .utils import load_nist_vectors, load_nist_vectors_from_file


def test_load_nist_vectors_encrypt():
    vector_data = textwrap.dedent("""
    # CAVS 11.1
    # Config info for aes_values
    # AESVS GFSbox test data for CBC
    # State : Encrypt and Decrypt
    # Key Length : 128
    # Generated on Fri Apr 22 15:11:33 2011

    [ENCRYPT]

    COUNT = 0
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6
    CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e

    COUNT = 1
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    PLAINTEXT = 9798c4640bad75c7c3227db910174e72
    CIPHERTEXT = a9a1631bf4996954ebc093957b234589

    [DECRYPT]

    COUNT = 0
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e
    PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6

    COUNT = 1
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    CIPHERTEXT = a9a1631bf4996954ebc093957b234589
    PLAINTEXT = 9798c4640bad75c7c3227db910174e72
    """).splitlines()

    assert load_nist_vectors(vector_data, "ENCRYPT",
        ["key", "iv", "plaintext", "ciphertext"],
    ) == [
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"f34481ec3cc627bacd5dc3fb08f273e6",
            b"0336763e966d92595a567cc9ce537f5e",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"9798c4640bad75c7c3227db910174e72",
            b"a9a1631bf4996954ebc093957b234589",
        ),
    ]


def test_load_nist_vectors_decrypt():
    vector_data = textwrap.dedent("""
    # CAVS 11.1
    # Config info for aes_values
    # AESVS GFSbox test data for CBC
    # State : Encrypt and Decrypt
    # Key Length : 128
    # Generated on Fri Apr 22 15:11:33 2011

    [ENCRYPT]

    COUNT = 0
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6
    CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e

    COUNT = 1
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    PLAINTEXT = 9798c4640bad75c7c3227db910174e72
    CIPHERTEXT = a9a1631bf4996954ebc093957b234589

    [DECRYPT]

    COUNT = 0
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    CIPHERTEXT = 0336763e966d92595a567cc9ce537f5e
    PLAINTEXT = f34481ec3cc627bacd5dc3fb08f273e6

    COUNT = 1
    KEY = 00000000000000000000000000000000
    IV = 00000000000000000000000000000000
    CIPHERTEXT = a9a1631bf4996954ebc093957b234589
    PLAINTEXT = 9798c4640bad75c7c3227db910174e72
    """).splitlines()

    assert load_nist_vectors(vector_data, "DECRYPT",
        ["key", "iv", "ciphertext", "plaintext"],
    ) == [
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"0336763e966d92595a567cc9ce537f5e",
            b"f34481ec3cc627bacd5dc3fb08f273e6",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"a9a1631bf4996954ebc093957b234589",
            b"9798c4640bad75c7c3227db910174e72",
        ),
    ]


def test_load_nist_vectors_from_file_encrypt():
    assert load_nist_vectors_from_file(
        "AES/KAT/CBCGFSbox128.rsp",
        "ENCRYPT",
        ["key", "iv", "plaintext", "ciphertext"],
    ) == [
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"f34481ec3cc627bacd5dc3fb08f273e6",
            b"0336763e966d92595a567cc9ce537f5e",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"9798c4640bad75c7c3227db910174e72",
            b"a9a1631bf4996954ebc093957b234589",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"96ab5c2ff612d9dfaae8c31f30c42168",
            b"ff4f8391a6a40ca5b25d23bedd44a597",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"6a118a874519e64e9963798a503f1d35",
            b"dc43be40be0e53712f7e2bf5ca707209",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"cb9fceec81286ca3e989bd979b0cb284",
            b"92beedab1895a94faa69b632e5cc47ce",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"b26aeb1874e47ca8358ff22378f09144",
            b"459264f4798f6a78bacb89c15ed3d601",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"58c8e00b2631686d54eab84b91f0aca1",
            b"08a4e2efec8a8e3312ca7460b9040bbf",
        ),
    ]


def test_load_nist_vectors_from_file_decypt():
    assert load_nist_vectors_from_file(
        "AES/KAT/CBCGFSbox128.rsp",
        "DECRYPT",
        ["key", "iv", "ciphertext", "plaintext"],
    ) == [
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"0336763e966d92595a567cc9ce537f5e",
            b"f34481ec3cc627bacd5dc3fb08f273e6",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"a9a1631bf4996954ebc093957b234589",
            b"9798c4640bad75c7c3227db910174e72",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"ff4f8391a6a40ca5b25d23bedd44a597",
            b"96ab5c2ff612d9dfaae8c31f30c42168",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"dc43be40be0e53712f7e2bf5ca707209",
            b"6a118a874519e64e9963798a503f1d35",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"92beedab1895a94faa69b632e5cc47ce",
            b"cb9fceec81286ca3e989bd979b0cb284",
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"459264f4798f6a78bacb89c15ed3d601",
            b"b26aeb1874e47ca8358ff22378f09144"
        ),
        (
            b"00000000000000000000000000000000",
            b"00000000000000000000000000000000",
            b"08a4e2efec8a8e3312ca7460b9040bbf",
            b"58c8e00b2631686d54eab84b91f0aca1"
        ),
    ]
{'fraction_non_alphanumeric': 0.06931886678722121, 'fraction_numerical': 0.4119198312236287, 'mean_word_length': 2.7378203323007604, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 96, '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': '6772843', 'n_tokens_mistral': 8662, 'n_tokens_neox': 4142, 'n_words': 516}