从文件下载此消息后,为什么加密消息的长度会发生变化?Python RSA加密/解密

时间:2014-06-25 22:55:52

标签: python encryption cryptography byte rsa

加密

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

  
    

打印(len(cryptow))倒数第二个字符串= 96

  

然后我将生成的密码保存在文件中:

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))仍然是96

之后,我重新编程并从文件中加载密码:

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))

  

打印(LEN(解密消息))   = 1那么为什么?

1 个答案:

答案 0 :(得分:0)

在线:

decrypt_message = decrypt_message.readlines()

列表分配给decrypt_message,其中列表中的每个项目都是文件中的一行;文件中只有一行...