Reputation: 498
Encryption
def encrypt():
k=0
l=1
length=len(message)/20
if int(length)>=1:
for i in range(int(length)+1):
message1=""
if i<int(length)+1:
i=k
message1=""
for j in range(20*i,20*(i+1)):
message1+=message[j]
k=i
message1=message1.encode()
print(len(message1))
crypto = rsa.encrypt(message1, pubkey)
text1.insert(END,crypto)
cryptow+=crypto
else:
message1=""
for i in range(len(message)-int(length)*20):
message1+=message[int(length)*20+i]
message1=message1.encode()
crypto = rsa.encrypt(message1, pubkey)
print(type(crypto))
text1.insert(END,crypto)
cryptow+=crypto
print(len(cryptow))
showinfo("Attention!","Message was encrypted")
message=2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
print(len(cryptow)) in penultimate string=96
then i save the resulting cipher in the file:
def save_encrypt_message():
filename = asksaveasfilename()
save_encrypt_message = open(filename,'wb')
print(len(cryptow))
save_encrypt_message = save_encrypt_message.write(cryptow)
save_encrypt_message.close()
print(len(cryptow)) still equally 96
After, i reran program and load cipher from file:
def open_message_for_decrypt():
filename = askopenfilename()
decrypt_message = open(filename,'rb')
decrypt_message = decrypt_message.readlines()
text1.delete('1.0', END)
text1.insert(END,decrypt_message)
print(len(decrypt_message))
and
print(len(decrypt_message)) =1 So WHY?
Upvotes: 0
Views: 63
Reputation: 122032
On the line:
decrypt_message = decrypt_message.readlines()
a list is assigned to decrypt_message
, where each item in the list is one line from the file; there's only one line in the file...
Upvotes: 0