@@ -23,33 +23,34 @@ def encrypt(mode, key, iv, plaintext):
2323
2424
2525def build_vectors (mode , filename ):
26- vector_file = open (filename , "r" )
27-
2826 count = 0
2927 output = []
3028 key = None
3129 iv = None
3230 plaintext = None
33- for line in vector_file :
34- line = line .strip ()
35- if line .startswith ("KEY" ):
36- if count != 0 :
37- output .append ("CIPHERTEXT = {}" .format (
38- encrypt (mode , key , iv , plaintext ))
39- )
40- output .append ("\n COUNT = {}" .format (count ))
41- count += 1
42- name , key = line .split (" = " )
43- output .append ("KEY = {}" .format (key ))
44- elif line .startswith ("IV" ):
45- name , iv = line .split (" = " )
46- iv = iv [0 :16 ]
47- output .append ("IV = {}" .format (iv ))
48- elif line .startswith ("PLAINTEXT" ):
49- name , plaintext = line .split (" = " )
50- output .append ("PLAINTEXT = {}" .format (plaintext ))
5131
52- output .append ("CIPHERTEXT = {}" .format (encrypt (mode , key , iv , plaintext )))
32+ with open (filename , "r" ) as vector_file :
33+ for line in vector_file :
34+ line = line .strip ()
35+ if line .startswith ("KEY" ):
36+ if count != 0 :
37+ output .append ("CIPHERTEXT = {}" .format (
38+ encrypt (mode , key , iv , plaintext ))
39+ )
40+ output .append ("\n COUNT = {}" .format (count ))
41+ count += 1
42+ name , key = line .split (" = " )
43+ output .append ("KEY = {}" .format (key ))
44+ elif line .startswith ("IV" ):
45+ name , iv = line .split (" = " )
46+ iv = iv [0 :16 ]
47+ output .append ("IV = {}" .format (iv ))
48+ elif line .startswith ("PLAINTEXT" ):
49+ name , plaintext = line .split (" = " )
50+ output .append ("PLAINTEXT = {}" .format (plaintext ))
51+ output .append (
52+ "CIPHERTEXT = {}" .format (encrypt (mode , key , iv , plaintext ))
53+ )
5354 return "\n " .join (output )
5455
5556
0 commit comments