The Below Program is very simple and written to encode and decode the name or any word .
save it as "ceaser_cipher.py"
Output :
Encoded Message : oqzrzmmz2knudr2oxsgnm
After Decode : prasanna loves python
save it as "ceaser_cipher.py"
# i am about to write program - ceaser cipher
cipher = {'a':'z' ,'b':'a', 'c':'b', 'd':'c', 'e':'d', 'f':'e', 'g':'f', 'h':'g', 'i':'h', 'j':'i', 'k':'j', 'l':'k', 'm':'l', 'n':'m', 'o':'n', 'p':'o', 'q':'p', 'r':'q', 's':'r', 't':'s', 'u':'t', 'v':'u', 'w':'v', 'x':'w', 'y':'x', 'z':'y',' ':'2'}
class ceaser_cipher:
def __init__(self, name_cip):
self.name_cip = name_cip
self.encoded = ""
self.decoded = ""
def encode(self):
global cipher
for ch in self.name_cip:
self.encoded += cipher[ch]
print self.encoded
def decode(self):
global cipher
for ch in self.encoded:
for key in cipher :
if ch == cipher[key]:
self.decoded += key
print self.decoded
def call():
ceaser = ceaser_cipher('prasanna loves python')
ceaser.encode()
ceaser.decode()
call()
Output :
Encoded Message : oqzrzmmz2knudr2oxsgnm
After Decode : prasanna loves python
Run the Program by calling : python ceaser_cipher.py (works normal in Linux and Mac Users )
For Windows users : save the file in the particular area of python and then invoke it in command prompt - python ceaser_cipher.py after changing to the desired location .
No comments:
Post a Comment