我试图创建一个python playfair密码,但在创建过程中遇到了一些问题。我有一张五乘五的桌子,上面有以下信息:
[['A', 'B', 'C', 'D', 'E'],
['F', 'G', 'H', 'I', 'Y'],
['K', 'L', 'M', 'N', 'O'],
['P', 'Q', 'R', 'S', 'T'],
['U', 'V', 'W', 'X', 'Z']]
我应该一次加密两封信。当给定输入encrypt(B,N)时,结果输出应该是DL。输入中的第一个字母应该返回与B在同一行中的字母,但它有N列。我希望有人能为我解释一种实现这一点的方法。你知道吗
在这里友好用户的帮助下,一些代码是这样的:
def find_index(letter, table):
for i,li in enumerate(table):
try:
j=li.index(letter)
return i,j
except ValueError:
pass
raise ValueError("'{}' not in matrix".format(letter))
print "Row:Column"
print find_index('I', table)
def encode(a, b):
if a == b:
print "ERROR: letters to encode_pair must be distinct"
print find_index (a,table)
print find_index (b, table)
您需要保存find_index(a,table)和find_index(a,table)的返回,如果我理解正确的话,这就是您需要实现的代码类型
最后的步骤可以一步完成,但我试图弄清楚,以确保你明白我在做什么,并纠正我,如果我误解了
那很有趣。。。谢谢。你知道吗
可以使用python中的ord()获取char的ASCII值。你知道吗
前
s='A'
更改\u s=chr(ord(s)+2)
所以结果出来的是变化
相关问题 更多 >
编程相关推荐