123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- def rsa(message,size):
- start = timer()
- key = RSA.generate(size)
- key_gen_time= timer() - start
-
- cipher = PKCS1_OAEP.new(key.publickey())
- buffer=""
- chunks=[]
- size=214
- parts=int(len(message)/size)
- x=0
- for i in range(parts):
- chunks.append(message[size*i:size*(i+1)])
- x=i
-
- chunks.append(message[(x+1)*size:])
- ciphers=[]
- start = timer()
- for chunk in chunks:
- chunk_bytes=chunk.encode("utf-8")
- ciphertext = cipher.encrypt(chunk_bytes)
- ciphers.append(ciphertext)
- encrypt_time=timer() - start
- #decryption
- cipher = PKCS1_OAEP.new(key)
- start = timer()
- for ciphertext in ciphers:
- pt = cipher.decrypt(ciphertext)
- buffer+=pt.decode("utf-8")
- decrypt_time = timer() - start
- if buffer==message:
- print("successfull encryption and decryption")
- else:
- print("Incorrect encryption/decryption")
- print("time taken for key gen ",(key_gen_time))
- print("time taken to encrypt ",(encrypt_time))
- print("Time Taken to Encrypt per byte is ",((encrypt_time)/len(message)))
- print("time taken to Decrypt ",(decrypt_time))
- print("Time Taken to Decrypt per byte is ",((decrypt_time)/len(message)))
-
- generateFiles()
- kbData=getData("kbfile.txt")
- mbData=getData("mbfile.txt")
- rsa(kbData,2048)
- rsa(mbData,2048)
|