Skip to content

Instantly share code, notes, and snippets.

@public
Created January 3, 2014 12:48
Show Gist options
  • Select an option

  • Save public/8237388 to your computer and use it in GitHub Desktop.

Select an option

Save public/8237388 to your computer and use it in GitHub Desktop.
SHA256 a8c806bfdbd6a30f21e42847caa5899426db5325a369ea4e429f0c7223224ac8
import binascii
import botan
BLOCK_SIZE = 64
def encrypt(key, iv, plaintext):
encryptor = botan.Cipher("IDEA/CFB", "encrypt",
binascii.unhexlify(key))
cipher_text = encryptor.cipher(binascii.unhexlify(plaintext),
binascii.unhexlify(iv))
return binascii.hexlify(cipher_text)
vector_file = open(
"../cryptography/tests/hazmat/primitives/vectors/ciphers/AES/CFB/CFB128MMT128.rsp",
"r"
)
count = 0
output = []
key = None
iv = None
plaintext = None
ct = None
for line in vector_file:
line = line.strip()
if line.startswith("KEY"):
if count != 0:
output.append("CIPHERTEXT = {}".format(
encrypt(key, iv, plaintext))
)
output.append("\nCOUNT = {}".format(count))
count += 1
name, key = line.split(" = ")
output.append("KEY = {}".format(key))
elif line.startswith("IV"):
name, iv = line.split(" = ")
iv = iv[:BLOCK_SIZE//8*2]
output.append("IV = {}".format(iv))
elif line.startswith("PLAINTEXT"):
name, plaintext = line.split(" = ")
output.append("PLAINTEXT = {}".format(plaintext))
output.append("CIPHERTEXT = {}".format(encrypt(key, iv, plaintext)))
print("\n".join(output))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment