回信加密

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
  1. import sys
  2.  
  3. alphabet = 'abcdefghijklmnopqrstuvwxyz'
  4.  
  5. class LetterBack:
  6. '''Class for Encrypting a string of letters'''
  7.  
  8. def __init__(self, text='mnm'):
  9. self.text = text
  10.  
  11. def encrypt(self, aSentance):
  12. '''Encrypts a given string by replacing each letter
  13. with the letter before it in the alphabet.'''
  14. output = ''
  15. for element in aSentance:
  16. for i in range(26):
  17. if element == alphabet[i]:
  18. output += alphabet[i-1]
  19. print output
  20.  
  21. def decrypt(self, aSentance):
  22. '''Decrypts a given string encoded by the encrypt
  23. function.'''
  24. output = ''
  25. for element in aSentance:
  26. #print element + ' this is 1'
  27. for i in range(26):
  28. if element == alphabet[i-1]:
  29. output += alphabet[i]
  30. print output
  31.  
  32. def main():
  33. lb = LetterBack()
  34. if sys.argv[1] == '-e':
  35. lb.encrypt(sys.argv[2])
  36. elif sys.argv[1] == '-d':
  37. lb.decrypt(sys.argv[2])
  38.  
  39. if __name__ == '__main__':
  40. main()

以上是关于回信加密的主要内容,如果未能解决你的问题,请参考以下文章

可以解密加密数据的片段吗?

数字签名数字证书对称加密算法非对称加密算法单向加密(散列算法)

数字签名数字证书对称加密算法非对称加密算法单向加密(散列算法)

给“习得性无助”者的回信

alex鸡汤回信

数字签名数字证书对称加密算法非对称加密算法单向加密(散列算法)——Web网络系列学习笔记