回信加密
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了回信加密相关的知识,希望对你有一定的参考价值。
simple encryption program written just for fun.Usage:
$ python letterback.py -e "alvin"
zkuhm
$ python letterback.py -d "zkuhm"
alvin
Or in the python interpreter.
In [1]: import letterback
In [2]: lb = letterback.LetterBack()
In [3]: lb.encrypt("alvin")
zkuhm
In [4]: lb.decrypt("zkuhm")
alvin
import sys alphabet = 'abcdefghijklmnopqrstuvwxyz' class LetterBack: '''Class for Encrypting a string of letters''' def __init__(self, text='mnm'): self.text = text def encrypt(self, aSentance): '''Encrypts a given string by replacing each letter with the letter before it in the alphabet.''' output = '' for element in aSentance: for i in range(26): if element == alphabet[i]: output += alphabet[i-1] print output def decrypt(self, aSentance): '''Decrypts a given string encoded by the encrypt function.''' output = '' for element in aSentance: #print element + ' this is 1' for i in range(26): if element == alphabet[i-1]: output += alphabet[i] print output def main(): lb = LetterBack() if sys.argv[1] == '-e': lb.encrypt(sys.argv[2]) elif sys.argv[1] == '-d': lb.decrypt(sys.argv[2]) if __name__ == '__main__': main()
以上是关于回信加密的主要内容,如果未能解决你的问题,请参考以下文章
数字签名数字证书对称加密算法非对称加密算法单向加密(散列算法)