Python 密码学 - 换位密码的加密
在上一章中,我们了解了换位密码。 在本章中,让我们讨论它的加密。
Pyperclip
Python编程语言中 pyperclip 插件的主要用途是执行跨平台模块,将文本复制粘贴到剪贴板。 您可以使用如图所示的命令安装 python pyperclip 模块
pip install pyperclip
如果该需求已经存在于系统中,可以看到如下输出 −
代码
以 pyperclip 为主模块的加密换位密码的 python 代码如下所示 −
import pyperclip
def main():
myMessage = 'Transposition Cipher'
myKey = 10
ciphertext = encryptMessage(myKey, myMessage)
print("Cipher Text is")
print(ciphertext + '|')
pyperclip.copy(ciphertext)
def encryptMessage(key, message):
ciphertext = [''] * key
for col in range(key):
position = col
while position < len(message):
ciphertext[col] += message[position]
position += key
return ''.join(ciphertext) #Cipher text
if __name__ == '__main__':
main()
输出
以 pyperclip 为主模块的换位密码的加密程序代码输出如下 −
说明
函数 main() 调用 encryptMessage(),其中包括使用 len 函数拆分字符并在 柱状格式。
main 函数在最后被初始化以获得适当的输出。

