55from cryptography .hazmat .primitives .asymmetric import padding
66from cryptography .hazmat .primitives .asymmetric import rsa
77from eth_keys import keys
8- from math import ceil
98
109block_size = AES .block_size
1110address_size = 20
@@ -21,7 +20,6 @@ def encrypt(key, plaintext):
2120
2221 # Ensure key size is 128 bits (16 bytes)
2322 if len (key ) != block_size :
24- print (len (key ), block_size )
2523 raise ValueError ("Key size must be 128 bits." )
2624
2725 # Create a new AES cipher block using the provided key
@@ -120,7 +118,10 @@ def build_input_text(plaintext, user_aes_key, sender, contract, function_selecto
120118 # Convert the ct to an integer
121119 int_cipher_text = int .from_bytes (ct , byteorder = 'big' )
122120
123- return int_cipher_text , signature
121+ return {
122+ 'ciphertext' : int_cipher_text ,
123+ 'signature' : signature
124+ }
124125
125126
126127def build_string_input_text (plaintext , user_aes_key , sender , contract , function_selector , signing_key ):
@@ -133,13 +134,12 @@ def build_string_input_text(plaintext, user_aes_key, sender, contract, function_
133134
134135 encoded_plaintext = bytearray (list (plaintext .encode ('utf-8' )))
135136
136- for i in range (ceil (len (encoded_plaintext ) / 8 )):
137- start_idx = i * 8
137+ for start_idx in range (0 , len (encoded_plaintext ), 8 ):
138138 end_idx = min (start_idx + 8 , len (encoded_plaintext ))
139139
140140 byte_arr = encoded_plaintext [start_idx :end_idx ] + bytearray (8 - (end_idx - start_idx ))
141141
142- ct_int , sig = build_input_text (
142+ it_int = build_input_text (
143143 int .from_bytes (byte_arr , 'big' ),
144144 user_aes_key ,
145145 sender ,
@@ -148,8 +148,8 @@ def build_string_input_text(plaintext, user_aes_key, sender, contract, function_
148148 signing_key
149149 )
150150
151- input_text ['ciphertext' ]['value' ].append (ct_int )
152- input_text ['signature' ].append (sig )
151+ input_text ['ciphertext' ]['value' ].append (it_int [ 'ciphertext' ] )
152+ input_text ['signature' ].append (it_int [ 'signature' ] )
153153
154154 return input_text
155155
0 commit comments