Python转置字母对scytale密码
因此,我有一些Python代码,可以运行Scytale Cipher的文本字符串, 但是,我试图转置字母对而不是单个字母。
plaintext = "abcdefghij"
Current Encoding:
a c e g i
b d f h j
Desired Encodeing:
ab ef ij
cd gh
当前结果=“ acegibdfhj”
理想结果=“ abefijcdgh”
脚本:
plaintext = "abcdefghij"
key = 2
ciphertext = [''] * key
for column in range(key):
pointer = column
while pointer < len(plaintext):
ciphertext[column] += plaintext[pointer]
pointer += key
print(plaintext)
print(''.join(ciphertext))
So I have some python code that runs the scytale cipher for a string of text,
However I am trying to transpose pairs of letters rather than single letters.
plaintext = "abcdefghij"
Current Encoding:
a c e g i
b d f h j
Desired Encodeing:
ab ef ij
cd gh
Current Outcome = "acegibdfhj"
Ideal Outcome = "abefijcdgh"
Script:
plaintext = "abcdefghij"
key = 2
ciphertext = [''] * key
for column in range(key):
pointer = column
while pointer < len(plaintext):
ciphertext[column] += plaintext[pointer]
pointer += key
print(plaintext)
print(''.join(ciphertext))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这
可能不是最有效的方法,但肯定是有效的。根据需要添加边界案例。在o(n)中运行
This works
May not be the most efficient way, but surely works. Add the boundary cases as you want. Runs in O(n)