Server IP : 162.240.98.243 / Your IP : 3.129.42.134 Web Server : Apache System : Linux server.bti.yaw.mybluehostin.me 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : btiyawmy ( 1003) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/python2-cryptography-1.7.2/docs/development/custom-vectors/idea/ |
Upload File : |
import binascii from cryptography.hazmat.backends.openssl.backend import backend from cryptography.hazmat.primitives.ciphers import algorithms, base, modes def encrypt(mode, key, iv, plaintext): cipher = base.Cipher( algorithms.IDEA(binascii.unhexlify(key)), mode(binascii.unhexlify(iv)), backend ) encryptor = cipher.encryptor() ct = encryptor.update(binascii.unhexlify(plaintext)) ct += encryptor.finalize() return binascii.hexlify(ct) def build_vectors(mode, filename): with open(filename, "r") as f: vector_file = f.read().splitlines() count = 0 output = [] key = None iv = None plaintext = None for line in vector_file: line = line.strip() if line.startswith("KEY"): if count != 0: output.append("CIPHERTEXT = {0}".format( encrypt(mode, key, iv, plaintext)) ) output.append("\nCOUNT = {0}".format(count)) count += 1 name, key = line.split(" = ") output.append("KEY = {0}".format(key)) elif line.startswith("IV"): name, iv = line.split(" = ") iv = iv[0:16] output.append("IV = {0}".format(iv)) elif line.startswith("PLAINTEXT"): name, plaintext = line.split(" = ") output.append("PLAINTEXT = {0}".format(plaintext)) output.append("CIPHERTEXT = {0}".format(encrypt(mode, key, iv, plaintext))) return "\n".join(output) def write_file(data, filename): with open(filename, "w") as f: f.write(data) CBC_PATH = "tests/hazmat/primitives/vectors/ciphers/AES/CBC/CBCMMT128.rsp" write_file(build_vectors(modes.CBC, CBC_PATH), "idea-cbc.txt") OFB_PATH = "tests/hazmat/primitives/vectors/ciphers/AES/OFB/OFBMMT128.rsp" write_file(build_vectors(modes.OFB, OFB_PATH), "idea-ofb.txt") CFB_PATH = "tests/hazmat/primitives/vectors/ciphers/AES/CFB/CFB128MMT128.rsp" write_file(build_vectors(modes.CFB, CFB_PATH), "idea-cfb.txt")