【发布时间】:2020-06-23 09:04:55
【问题描述】:
当用户提供密钥和cipher_text时,我想照常将密文解密为明文
这是我的代码:
from Crypto.Cipher import DES
key = input('Enter your key: ').encode('utf-8')
myDes = DES.new(key, DES.MODE_ECB)
print('Please select option:\n1. Encryption\n2. Decryption\n3. Exit')
while True:
user_choice = input("Choose a option: ")
if user_choice == "1":
plain_text = input("Please enter your text: ")
modified_plain_text = plain_text.encode("utf-8")
cipher_text = myDes.encrypt(plain_text.encode("utf-8"))
print(f"Encrypted text: {cipher_text}")
elif user_choice == "2":
user_cipher_text = input(
"Please enter your cipher text: ").encode('utf-8')
text = myDes.decrypt(user_cipher_text, DES.block_size)
elif user_choice == "3":
print("Quitting The Program....")
break
else:
print("Please Choose a correct option")
但是当我运行它时,我得到一个错误:
Traceback (most recent call last):
File "C:\Users\Manish\Downloads\DES.py", line 17, in <module>
text = myDes.decrypt(user_cipher_text,DES.block_size)
File "C:\python38\lib\site-packages\Crypto\Cipher\_mode_ecb.py", line 183, in decrypt
raise TypeError("output must be a bytearray or a writeable memoryview")
TypeError: output must be a bytearray or a writeable memoryview
【问题讨论】:
标签: python cryptography des