Advertisement
Guest User

(lg) King Caeser Cipher

a guest
Oct 30th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #python3
  2. class CaeserCipher(object):
  3.     """A pythonic implementation of CaserCipher"""
  4.     def __init__(self, offset):
  5.         self.offset = offset
  6.  
  7.     def encode(self, message):
  8.         """/
  9.         Take a message and encode it buy adding the offset value to each charecter.
  10.         """
  11.         return ''.join([chr(ord(i)+self.offset) for i in message])
  12.  
  13.     def decode(self, message):
  14.         """/
  15.         Take an encoded message and decode it by removing the offset
  16.         """
  17.         return ''.join([chr(ord(i)-self.offset) for i in message])
  18.  
  19. if __name__ == '__main__':
  20.     caeser = CaeserCipher(3)
  21.     message = "Your momma's ass"
  22.     encoded = caeser.encode(message)
  23.     print("Message: " + message)
  24.     print("Encoded: " + encoded)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement