在上一章中,我们了解了Transposition Cipher.在本章中,我们将讨论它的加密.
Pyperclip
Python编程语言中 pyperclip 插件的主要用法是执行跨平台模块,用于将文本复制和粘贴到剪贴板.您可以使用如下所示的命令安装python pyperclip 模块
pip install pyperclip
如果系统中已存在该要求,您可以看到以下输出 :
代码
用于加密转置密码的python代码,其中pyperclip是主要模块,如下所示 :
import pyperclipdef 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 textif __name__ == '__main__': main()
输出
用于加密转置密码的程序代码,其中 pyperclip 是主模块提供以下输出 :
解释
函数 main()调用 encryptMessage(),其中包括使用 len 函数拆分字符并以柱状格式迭代它们的过程.
主函数在结尾处初始化以获得适当的输出.