换位密码加密
在前一章节中,我们学习了换位密码。本章节,让我们讨论一下它的加密方式。
Pyperclip
Python 编程语言中 pyperclip 插件主要用于执行跨平台模块以将文本复制并粘贴到剪贴板。你可以使用如下所示的命令安装 python 的 pyperclip 模块
pip install pyperclip
如果系统中已经包含该需求,你可以看到以下输出 −
代码
下面给出换位密码加密的 python 代码,其中 pyperclip 是主要模块 −
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 函数拆分字符并在列格式中迭代字符的过程。
主函数在最后初始化,以获得合适的输出。
广告