@@ -21,7 +21,6 @@ def encrypt(key, plaintext):
2121
2222 # Ensure key size is 128 bits (16 bytes)
2323 if len (key ) != block_size :
24- print (len (key ), block_size )
2524 raise ValueError ("Key size must be 128 bits." )
2625
2726 # Create a new AES cipher block using the provided key
@@ -120,7 +119,10 @@ def build_input_text(plaintext, user_aes_key, sender, contract, function_selecto
120119 # Convert the ct to an integer
121120 int_cipher_text = int .from_bytes (ct , byteorder = 'big' )
122121
123- return int_cipher_text , signature
122+ return {
123+ 'ciphertext' : int_cipher_text ,
124+ 'signature' : signature
125+ }
124126
125127
126128def build_string_input_text (plaintext , user_aes_key , sender , contract , function_selector , signing_key ):
@@ -133,13 +135,12 @@ def build_string_input_text(plaintext, user_aes_key, sender, contract, function_
133135
134136 encoded_plaintext = bytearray (list (plaintext .encode ('utf-8' )))
135137
136- for i in range (ceil (len (encoded_plaintext ) / 8 )):
137- start_idx = i * 8
138+ for start_idx in range (0 , len (encoded_plaintext ), 8 ):
138139 end_idx = min (start_idx + 8 , len (encoded_plaintext ))
139140
140141 byte_arr = encoded_plaintext [start_idx :end_idx ] + bytearray (8 - (end_idx - start_idx ))
141142
142- ct_int , sig = build_input_text (
143+ it_int = build_input_text (
143144 int .from_bytes (byte_arr , 'big' ),
144145 user_aes_key ,
145146 sender ,
@@ -148,8 +149,8 @@ def build_string_input_text(plaintext, user_aes_key, sender, contract, function_
148149 signing_key
149150 )
150151
151- input_text ['ciphertext' ]['value' ].append (ct_int )
152- input_text ['signature' ].append (sig )
152+ input_text ['ciphertext' ]['value' ].append (it_int [ 'ciphertext' ] )
153+ input_text ['signature' ].append (it_int [ 'signature' ] )
153154
154155 return input_text
155156
0 commit comments