我想浏览一个表上的列表,该表采用另一个列表的坐标。但它返回一个错误:“'int'对象不可下标”,即使我更改了列表
Text = [
["B","o","n","j"],
["o","u","r"," "],
["ç","a","v","a"],
["b","i","e","n"],
]
Cle = [
['2','5','6','7'],
['9','3','1','5'],
['7','1','7','8'],
['8','4','3','0'],
]
for a in range(0,4):
for b in range(0,4):
Text[a][b] = ( int( ord(Text[a][b])) ^int(Cle[a][b]))
def Affichage(TextAffichage):
print('[[', '],\n['.join([','.join(["'{:4}'".format(item) for item in row]) for row in TextAffichage]))
print("],\n]")
Affichage(Text)
print("*"*30)
# Substitution of the text with a data box de in decimal base
SBOX = [
['77', '23', '4', '34', '26', '34', '81', '70', '26', '86'],
['64', '96', '66', '28', '4', '2', '21', '90', '79', '83'],
['25', '13', '60', '63', '82', '36', '86', '69', '43', '17'],
['13', '80', '21', '62', '80', '92', '62', '9', '69', '40'],
['21', '76', '90', '10', '28', '32', '21', '33', '18', '56'],
['73', '50', '56', '53', '1', '7', '96', '52', '59', '98'],
['13', '80', '98', '90', '19', '30', '35', '52', '10', '55'],
['23', '85', '57', '42', '64', '50', '30', '92', '74', '86'],
['79', '4', '60', '50', '26', '76', '78', '55', '14', '32'],
['76', '43', '89', '12', '36', '49', '23', '28', '64', '37']]
x = []
y = []
Texte = []
for i in range(0,4):
for m in range(0,4):
x = (Text[i][m][0])
y = (Text[i][m][1])
Texte(i)[m] = SBOX[int(x)][int(y)]
Affichage(Text)
它返回的内容:
[[ ' 64',' 106',' 104',' 109'],
[' 102',' 118',' 115',' 37'],
[' 224',' 96',' 113',' 105'],
[' 106',' 109',' 102',' 110'
],
]
******************************
Traceback (most recent call last):
File "C:Downloads\petit test sur texte.py", line 59, in <module>
x = (Text[i][m][0])
TypeError: 'int' object is not subscriptable
Text[i][m][0]
的问题是Text[i][m]
是一个整数,如下所示,并且错误表明您不能为整数下标。在这里你可以看到Text
只是二维的,这就是为什么Text[i][m][0]
不起作用;它试图在第三维度上建立索引我不知道你为什么期望文本是三维的
相关问题 更多 >
编程相关推荐