-
Notifications
You must be signed in to change notification settings - Fork 0
/
pycaesarcrypt.py
37 lines (28 loc) · 1005 Bytes
/
pycaesarcrypt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# # -*- coding: utf-8 -*-
__version__ = '1.0.0'
class pycaesarcrypt(object):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
def caesar(self, string, shift):
result = ''
for char in string:
if char.isalpha():
index = (self.alphabet.find(char.lower()) + shift) % 26
if char.isupper():
result += self.alphabet[index].upper()
else:
result += self.alphabet[index]
else:
result += char
return result
def encrypt(self, plaintext, shift):
return self.caesar(plaintext, shift)
def decrypt(self, chiffre, shift):
return self.caesar(chiffre, -shift)
def rot13(self, string, mode=True):
if mode is True:
return self.encrypt(string, 13)
else:
return self.decrypt(string, 13)
if __name__ == '__main__':
print('You have to import this module in order to use it.')