Python实现换位加密
生活随笔
收集整理的這篇文章主要介紹了
Python实现换位加密
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import math
def transpostionEncrypt(msg,key):#加密size = len(msg)result = []for i in range(key):t = iwhile t<size:result.append(msg[t])t+=keyreturn ''.join(result)
def transpostionDecrypt(msg,key):#解密numOfColums = int(math.ceil(len(msg)/float(key)))numOfRows = keysharedBox = numOfColums*numOfRows - len(msg)row = 0col = 0result = ['']*numOfColumsfor i in msg:result[col] += icol+=1if col==numOfColums or (col==numOfColums-1 and row>=numOfRows-sharedBox):col=0row+=1return ''.join(result)def main():cipher = transpostionEncrypt("Common sense is not so common.",8)print cipher#密文print transpostionDecrypt(cipher,8)
if __name__=="__main__":main()
總結
以上是生活随笔為你收集整理的Python实现换位加密的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python获取android手机信息
- 下一篇: python获取docx文档的内容(文本