gpt4 book ai didi

python - 我的解密程序做错了事

转载 作者:行者123 更新时间:2023-12-01 02:53:01 25 4
gpt4 key购买 nike

今天我制作了一个 .py 文件,用于解密使用维吉尼亚方 block 加密的字符串。我已经到目前为止,但我似乎无法向密码列表和 encr_txt 添加空格,因为它会混淆解密的消息。你得到的不是“消息是,你好,我的名字是 slim shady”,而是“消息是,hellprvmwhwebwrw k d thady”,就好像我在 encr_txt 和密码列表中留了空格一样,我收到了一条很好的消息。我不知道如何解决这个问题,也没有错误,我几天前才开始用 python 编码,所以如果它很明显,我很抱歉。我也知道这可以更容易地完成,但我正在学习列表,所以我选择这样做而不是这样的:

<a href="https://stackoverflow.com/questions/35711747/ascii-vigenere-cipher-not-decrypting-properly">Another question i found relating my problem but does not describe my situation</a>

代码:

# -*- coding: utf-8 -*-
# ^ encoding

# Encrypted text
# encr_txt = 'tkedobaxoudqrrffhhhalbmmcnedeo'
encr_txt = 'qexpg vy zeen ie wdrm elsmy'
#encr_list = list(encr_txt)
txtpos = 0
# Key to ^
key = 'james'
keypos = 0

limit = len(encr_txt)
limitpos = 0
# Vigenere square
ciphr = ['abcdefghijklmnopqrstuvwxyz ',
'bcdefghijklmnopqrstuvwxyz a',
'cdefghijklmnopqrstuvwxyz ab',
'defghijklmnopqrstuvwxyz abc',
'efghijklmnopqrstuvwxyz abcd',
'fghijklmnopqrstuvwxyz abcde',
'ghijklmnopqrstuvwxyz abcdef',
'hijklmnopqrstuvwxyz abcdefg',
'ijklmnopqrstuvwxyz abcdefgh',
'jklmnopqrstuvwxyz abcdefghi',
'klmnopqrstuvwxyz abcdefghij',
'lmnopqrstuvwxyz abcdefghijk',
'mnopqrstuvwxyz abcdefghijkl',
'nopqrstuvwxyz abcdefghijklm',
'opqrstuvwxyz abcdefghijklmn',
'pqrstuvwxyz abcdefghijklmno',
'qrstuvwxyz abcdefghijklmnop',
'rstuvwxyz abcdefghijklmnopq',
'stuvwxyz abcdefghijklmnopqr',
'tuvwxyz abcdefghijklmnopqrs',
'uvwxyz abcdefghijklmnopqrst',
'vwxyz abcdefghijklmnopqrstu',
'wxyz abcdefghijklmnopqrtsuv',
'xyz abcdefghijklmnopqrtsuvw',
'yz abcdefghijklmnopqrtsuvwx',
'z abcdefghijklmnopqrtsuvwxy',
'abcdefghijklmnopqrtsuvwxyz ']

first = ciphr[0]
string = ''


def start():
global limitpos
limitpos += 1
global keypos
for i in ciphr:
if keypos == len(key):
keypos = 0
else:
pass
if i[0] == key[keypos]:
#print "%s, %s" % (i[0], i)
global currenti
currenti = i
#print currenti
finder()
break
else:
pass

def finder():
global keypos
global txtpos
done = False
position = 0
while done == False:
for i in currenti[position]:
if i == '_':
pass

if i == encr_txt[txtpos]:
global string
string = string + first[position]
#print "message is, %s" % string
keypos += 1
txtpos += 1

done = True
if limitpos == limit:
print "message is, %s" % string
break
else:
start()
else:
position += 1
pass

start()

最佳答案

向表中添加空格会改变密码的工作方式。您不能期望进行这种更改而不影响消息的加密和解密方式!

顺便说一句,表格的最后一行不正确。它与第一行相同,但第一个位置应该有空格。

关于python - 我的解密程序做错了事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44511272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com