试图强行使用Ceasar密码,无法将正确的字符添加到应用程序

2024-06-26 14:14:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让我的代码环绕字母表,例如Z+1 should=A。相反,我得到的是非英语字符的垃圾值。如何使我的代码只使用字母表而不使用垃圾字符?你知道吗

enc = "Lbh ner havdhr va gur jbeyq n sevraq yvxr ab bgure Vg vf fb nznmvat gung jr unir fb zhpu va pbzzba fb lbhe unccvarff vf nyfb zvar"
blankList = [] #create the empty list
count = -30
while count < 40: #if less than 40 continue
    dec = ''  #empty string  
    for i in enc: #iterarte through
        a = ord(i)  #convert
        b = a + count # create var to store it 
        dec += chr(b) #to letter
    count += 1 #increment count 
    blankList.append(dec)

for i in blankList: #go through blank list
    print i #prints each on own line

Tags: 代码forfbcountcreate字符dec字母表
1条回答
网友
1楼 · 发布于 2024-06-26 14:14:05

您收到的是“垃圾”字符,因为您要求chr()将值转换为非正常打印字符。这是因为您没有正确地环绕字母表的边缘。你知道吗

一个简单的方法是运行:

for i in range(255):
    print(i, chr(i))

这将打印ASCII码和ASCII字符。那些以\x前缀列出的字符是十六进制的ASCII值,因为通常不打印字符。许多ASCII字符用于控制代码和终端的其他内容。你知道吗

一旦你修复了超过ord('z')的值的边包装,那么你应该得到一个句柄。您还只需要尝试25个变体,因为字母表中只有25个字符可以作为此字符串的其他值。你知道吗

相关问题 更多 >