Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class cipher(object):
- alphabet = 'abcdefghijklmnopqrstuvwxyz'
- cipheralphabet = 'abcdefghijklmnopqrstuvwxyz'
- def __init__(self, key='', type='Null'):
- self.key = key
- self.type = type
- def __str__(self):
- return self.type + " cipher"
- def encrypt(self, message):
- result = ''
- for ch in message:
- x = self.alphabet.find(ch)
- if x != -1:
- result += self.cipheralphabet[x]
- else:
- result += ch
- return result
- def decrypt(self, message):
- result = ''
- for ch in message:
- x = self.cipheralphabet.find(ch)
- if x != -1:
- result += self.alphabet[x]
- else:
- result += ch
- return result
- class cipher (Cipher):
- def __init__(self, key=3, type="Caesar"):
- self.key = key
- self.type = type
- self.cipher_alphabet = self.alphabet[self.key:] + self.alphabet[0:self.key]
- caesar = CaesarCipher(3, "Caesar")
- secret = caesar.encrypt("hello this is a test")
- print (secret)
- #khoor wklv lv d whvw
- print ( caesar.decrypt(secret))
- #hello this is a test
- secret = caesar.encrypt("abcdefghijklmnopqrstuvwxyz")
- print (secret)
- #defghijklmnopqrstuvwxyzabc
- print (caesar.decrypt(secret))
- #abcdefghijklmnopqrstuvwxyz
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement