gpt4 book ai didi

python - 对于Kasiski Test,如何在Python中实现26x26表

转载 作者:太空宇宙 更新时间:2023-11-04 09:06:47 25 4
gpt4 key购买 nike

这是表格 http://en.wikipedia.org/wiki/File:Vigen%C3%A8re_square_shading.svg

如何在 Python 中实现此表?有什么办法吗?

关于如何检查行的任何线索:L 和 G 列欢迎使用 R。

最佳答案

>>> letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> mat = [(letters * 2)[i:i+26] for i in range(26)]
>>> print '\n'.join(mat)
ABCDEFGHIJKLMNOPQRSTUVWXYZ
BCDEFGHIJKLMNOPQRSTUVWXYZA
CDEFGHIJKLMNOPQRSTUVWXYZAB
DEFGHIJKLMNOPQRSTUVWXYZABC
EFGHIJKLMNOPQRSTUVWXYZABCD
FGHIJKLMNOPQRSTUVWXYZABCDE
GHIJKLMNOPQRSTUVWXYZABCDEF
HIJKLMNOPQRSTUVWXYZABCDEFG
IJKLMNOPQRSTUVWXYZABCDEFGH
JKLMNOPQRSTUVWXYZABCDEFGHI
KLMNOPQRSTUVWXYZABCDEFGHIJ
LMNOPQRSTUVWXYZABCDEFGHIJK
MNOPQRSTUVWXYZABCDEFGHIJKL
NOPQRSTUVWXYZABCDEFGHIJKLM
OPQRSTUVWXYZABCDEFGHIJKLMN
PQRSTUVWXYZABCDEFGHIJKLMNO
QRSTUVWXYZABCDEFGHIJKLMNOP
RSTUVWXYZABCDEFGHIJKLMNOPQ
STUVWXYZABCDEFGHIJKLMNOPQR
TUVWXYZABCDEFGHIJKLMNOPQRS
UVWXYZABCDEFGHIJKLMNOPQRST
VWXYZABCDEFGHIJKLMNOPQRSTU
WXYZABCDEFGHIJKLMNOPQRSTUV
XYZABCDEFGHIJKLMNOPQRSTUVW
YZABCDEFGHIJKLMNOPQRSTUVWX
ZABCDEFGHIJKLMNOPQRSTUVWXY

或者,您可以即时计算元素:

def get_elem(row, col):
return 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[(ord(row) + ord(col)) % 26]

print get_elem('L', 'G')

关于python - 对于Kasiski Test,如何在Python中实现26x26表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19882621/

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