/ Published in: Python
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
Expand |
Embed | Plain Text
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()
You need to login to post a comment.
