Last active
August 24, 2023 20:24
-
-
Save roshii/23f474394381093ba5ee814c1cb4fa6d to your computer and use it in GitHub Desktop.
NIST AES test vectors parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read the raw text from a file | |
with open("input.txt", "r") as file: | |
raw_text = file.read() | |
lines = raw_text.strip().split("\n") # Split into lines | |
data = [] | |
current_operation = None | |
OPERATION = "encrypt" # Amend to required operation | |
for line in lines[1:]: # Skip the first line | |
if line.startswith("F."): | |
if current_operation: | |
data.append(current_operation) | |
operation = line.split(".")[-1].lower() | |
if operation == OPERATION: | |
current_operation = {"key": "", "iv": "", "ciphertext": "", "plaintext": ""} | |
else: | |
current_operation = None | |
elif current_operation: | |
if line.startswith("Key") or line.startswith("IV"): | |
key, value = line.split(" ", 1) | |
current_operation[key.lower()] = value.strip() | |
else: | |
key, value = line.split(" ", 1) | |
key = key.lower() | |
value = value.strip() | |
if key in {"ciphertext", "plaintext"}: | |
current_operation[key] += value | |
# Append the operation | |
if current_operation: | |
data.append(current_operation) | |
# Transform the data to pytest parmaetrize format | |
keys = ", ".join(data[0].keys()) | |
values = [] | |
for entry in data: | |
values.append(tuple(entry.values())) | |
result = (keys, values) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment