【发布时间】:2015-01-31 16:10:34
【问题描述】:
我在向用户显示我的八字符密钥时遇到问题,我希望程序只显示最后一行,但我不知道如何。
输出如下:
这个程序有三个选择。
加密消息。
解密消息。
退出程序。
Make your choice: 1
以下文本将被加密:
在拉曼恰的某个地方,在一个我不想记住名字的地方,不久前住着一位绅士,他在架子上放着长矛和古老的盾牌,养着一只瘦马和一只赛狗。
This is your eight character key.
['H']
The last row is your eight character key.
['H', 'D']
This is your eight character key.
['H', 'D', 'z']
This is your eight character key.
['H', 'D', 'z', '#']
The last row is your eight character key.
['H', 'D', 'z', '#', "'"]
This is your eight character key.
['H', 'D', 'z', '#', "'", 'y']
This is your eight character key.
['H', 'D', 'z', '#', "'", 'y', 'i']
This is your eight character key.
['H', 'D', 'z', '#', "'", 'y', 'i', '1']
对于这个程序,我想要的只是打印八个字符键的最后一行。如果你们更改输出,我不介意。请记住,您需要查看的代码位于名为“EncryptCode”的过程中 我的代码如下所示:
import random
with open ("E:\Controlled Assessment CS\Controlled Assessment Sample.txt",mode="r",encoding="utf=8") as encrypt_file:
encrypt = encrypt_file.read()
def EncryptCode():
print ("This text below will be encrypted:")
printMessage(encrypt)
eightNumKey = 0
ASCIINumber = []
ASCIIKey = []
while eightNumKey !=8:
eightNumKey = eightNumKey + 1
RandomNumber = random.randint(33,126)
ASCIINumber.append(RandomNumber)
RandomCharacter = chr(RandomNumber)
ASCIIKey.append(RandomCharacter)
print ("This is your eight character key. \n",ASCIIKey)
def showMenu():
choice = input("\n\nMake your choice: ")
if choice == "1":
EncryptCode()
showMenu()
elif choice == "2":
DecryptCode()
showMenu()
elif choice not in ["1","2","3"]:
print(choice,"Is not one of the choices")
showMenu()
print("This program has three choices.")
print("\n1. Encrypt a message.")
print("\n2. Decrypt the message.")
print("\n3. Exit the program.")
showMenu()
【问题讨论】:
标签: python encryption