gpt4 book ai didi

python - python 中替换解密的错误

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


import random
orig=list(range(1,65))
temp_orig= [[0, 1, 2, 3, 4, 5, 6, 7],
[8, 9, 10, 11, 12, 13, 14, 15],
[16, 17, 18, 19, 20, 21, 22, 23],
[24, 25, 26, 27, 28, 29, 30, 31],
[32, 33, 34, 35, 36, 37, 38, 39],
[40, 41, 42, 43, 44, 45, 46, 47],
[48, 49, 50, 51, 52, 53, 54, 55],
[56, 57, 58, 59, 60, 61, 62, 63]]<p></p>

<p>ip= [[40, 24, 9, 41, 42, 56, 43, 45],
[4, 23, 21, 60, 35, 6, 59, 0],
[36, 53, 32, 16, 7, 37, 17, 18],
[10, 62, 61, 38, 29, 34, 31, 25],
[54, 57, 51, 49, 39, 3, 50, 30],
[11, 46, 33, 27, 44, 15, 13, 48],
[12, 58, 1, 26, 47, 20, 28, 52],
[19, 55, 2, 63, 22, 8, 14, 5]]</p>

<p>ipinv=[[15, 50, 58, 37, 8, 63, 13, 20],
[61, 2, 24, 40, 48, 46, 62, 45],
[19, 22, 23, 56, 53, 10, 60, 9],
[1, 31, 51, 43, 54, 28, 39, 30],
[18, 42, 29, 12, 16, 21, 27, 36],
[0, 3, 4, 6, 44, 7, 41, 52],
[47, 35, 38, 34, 55, 17, 32, 57],
[5, 33, 49, 14, 11, 26, 25, 59]]</p>

<p>print "\n\nOriginal position of Bits:"
for i in range(len(ipinv)):
print "\t",temp_orig[i]
print "\n\nInitial Permutation Table"
for i in range(len(ipinv)):
print "\t",ip[i]
print "\n\nInverse Initail permutation Table"
for i in range(len(ipinv)):
print "\t",ipinv[i]</p>

<p>print "\nRound 1:Initial Permutation"</p>

<p>plaintext=list(raw_input("\n\tEnter not more than 8 char:"))</p>

<p>l=len(plaintext)
for i in range(8,len(plaintext)):
del plaintext[l-1+8-i]</p>

<p>print "\n\tPlain text:",plaintext,"\n"</p>

<p>for i in range(8):
plaintext[i]=list(bin(ord(plaintext[i])).zfill(8))
print "\t",plaintext[i]</p>

<p>ip1=temp_orig
for i in range(8):
for j in range(8):
ip1[i][j]=plaintext[(ip[i][j])/8][(ip[i][j])%8]</p>

<p>print "\nEnciphered list:"
for i in range(8):
print "\t",ip1[i]
print "\n73\n",ip1[7][3],"\n73"</p>

<p>ip1_d=temp_orig</p>

<p>for i in range(8):
for j in range(8):
ip1_d[i][j]=ip1[(ipinv[i][j])/8][(ipinv[i][j])%8]
print ip1[7][3],"ip1_d",[i],[j],"=ip1[",(ipinv[i][j])/8,"][",(ipinv[i][j])%8,"]"
#print "ip1_d",[i],[j],"=",ip1[(ipinv[i][j])/8][(ipinv[i][j])%8]</p>

<p>print "\nDeciphered list:"
for i in range(8):
print "\t",ip1_d[i] </p>

de sunstitution 变得错误,例如我尝试打印 ip1[7][3] ,当 i=7j=3 没有对 ip1 进行任何分配

最佳答案

您执行ip1=temp_orig几次。这告诉我,您可能认为这会复制 temp_orig 列表 - 但事实并非如此。您必须在此处明确复制列表:

ip1=[list(row) for row in temp_orig]

等等。您的代码只是为 temp_orig 提供了新名称,但仍然修改了 temp_orig 列表。

我认为这是我一段时间以来见过的最困惑的代码。您应该开始更多地考虑数据转换,而不是像这样处理索引。我仍然不知道你的代码是做什么的或者它应该如何工作。

关于python - python 中替换解密的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5133953/

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