Skip to content

Commit 5a3ec6d

Browse files
committed
v1.0.6 release
1 parent bebac8e commit 5a3ec6d

File tree

5 files changed

+57
-74
lines changed

5 files changed

+57
-74
lines changed

decrypto/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from .ascii_cipher import AsciiCipher
2+
from .bacon_cipher import BaconCipher
3+
from .base64_cipher import Base64Cipher
24
from .binary_cipher import BinaryCipher
35
from .caesar_cipher import CaesarCipher
46
from .hexadecimal_cipher import HexadecimalCipher
57
from .morse_code_cipher import MorseCodeCipher
68
from .octal_cipher import OctalCipher
79
from .reverse_cipher import ReverseCipher
810
from .roman_numeral_cipher import RomanNumeralCipher
11+
from .rot13_cipher import ROT13Cipher
912
from .vigenere_cipher import VigenereCipher
10-
from .base64_cipher import Base64Cipher

decrypto/bacon_cipher.py

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,34 @@
1-
class BaconCipher:
2-
def __init__(self) -> None:
3-
self.baco_dict = {
4-
'A':'aaaaa', 'B':'aaaab', 'C':'aaaba',
5-
'D':'aaabb', 'E':'aabaa', 'F':'aabab',
6-
'G':'aabba', 'H':'aabbb', 'I':'abaaa',
7-
'J':'abaab', 'K':'ababa', 'L':'ababb',
8-
'M':'abbaa', 'N':'abbab', 'O':'abbba',
9-
'P':'abbbb', 'Q':'baaaa', 'R':'baaab',
10-
'S':'baaba', 'T':'baabb', 'U':'babaa',
11-
'V':'babab', 'W':'babba', 'X':'babbb',
12-
'Y':'bbaaa', 'Z':'bbaab'
1+
class BaconCipher:
2+
def __init__(self):
3+
'''This is python implementation of Bacon Cipher'''
4+
5+
self.bacon_dict = {
6+
'A': 'aaaaa', 'B': 'aaaab', 'C': 'aaaba',
7+
'D': 'aaabb', 'E': 'aabaa', 'F': 'aabab',
8+
'G': 'aabba', 'H': 'aabbb', 'I': 'abaaa',
9+
'J': 'abaab', 'K': 'ababa', 'L': 'ababb',
10+
'M': 'abbaa', 'N': 'abbab', 'O': 'abbba',
11+
'P': 'abbbb', 'Q': 'baaaa', 'R': 'baaab',
12+
'S': 'baaba', 'T': 'baabb', 'U': 'babaa',
13+
'V': 'babab', 'W': 'babba', 'X': 'babbb',
14+
'Y': 'bbaaa', 'Z': 'bbaab'
15+
}
16+
17+
self.reverse_bacon = {
18+
self.bacon_dict[key]: key for key in self.bacon_dict
1319
}
14-
self.reverse_baco = {
15-
self.baco_dict[key] : key for key in self.baco_dict }
1620

17-
def encrypt(self, message : str) -> str:
18-
cipher = ''
19-
for letter in message.upper():
20-
# checks for space
21-
if(letter != ' '):
22-
# adds the ciphertext corresponding to the
23-
# plaintext from the dictionary
24-
cipher += self.baco_dict[letter]
25-
else:
26-
# adds space
27-
cipher += ' '
28-
return cipher
21+
def encrypt(self, message: str) -> str:
22+
'''Encrypt plain text based upon the above bacon dict'''
23+
result = ''
24+
for ch in message.upper():
25+
result += self.bacon_dict.get(ch, '')
26+
result += ' '
27+
return result.strip()
2928

30-
def decrypt(self,message):
31-
decipher = ''
32-
i = 0
33-
while True :
34-
if(i < len(message)-4):
35-
# extracting a set of ciphertext
36-
# from the message which is of size 5
37-
substr = message[i:i + 5]
38-
# checking for space as the first
39-
# character of the substring
40-
if(substr[0] != ' '):
41-
decipher += self.reverse_baco[substr]
42-
i += 5 # to get the next set of ciphertext
43-
else:
44-
# adds space
45-
decipher += ' '
46-
i += 1 # index next to the space
47-
else:
48-
break
49-
return decipher
29+
def decrypt(self, message: str) -> str:
30+
'''Decrypt plain text based upon the above reverse bacon dict'''
31+
result = ''
32+
for encoded in message.split(' '):
33+
result += self.reverse_bacon.get(encoded, ' ')
34+
return result

decrypto/base64_cipher.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import base64 as b
1+
import base64
22

33

44
class Base64Cipher:
@@ -7,14 +7,14 @@ def __init__(self) -> None:
77

88
@staticmethod
99
def encrypt(msg: str) -> str:
10-
result = msg.encode('ascii')
11-
base64_bytes = b.b64encode(result)
10+
encoded = msg.encode('ascii')
11+
base64_bytes = base64.b64encode(encoded)
1212
result = base64_bytes.decode("ascii")
1313
return result
1414

1515
@staticmethod
1616
def decrypt(msg: str) -> str:
17-
result = msg.encode('ascii')
18-
sample_string_bytes = b.b64decode(result)
17+
encoded = msg.encode('ascii')
18+
sample_string_bytes = base64.b64decode(encoded)
1919
result = sample_string_bytes.decode("ascii")
2020
return result

decrypto/rot13_cipher.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
class ROT13Cipher:
22
def __init__(self) -> None:
3-
pass
3+
'''This is python implementation of ROT13 Cipher'''
44

5-
def encrypt(self, message):
6-
cipher = ''
7-
for letter in message.upper():
8-
# checking for space
9-
if(letter != ' '):
10-
num = chr((ord(letter) - ord('A') + 13 ) % 26 + ord('A'))
11-
cipher += num
5+
def encrypt(self, message: str) -> str:
6+
result = ''
7+
for ch in message.upper():
8+
if ch.isalpha():
9+
encoded = chr((ord(ch) - ord('A') + 13) % 26 + ord('A'))
10+
result += encoded
1211
else:
13-
# adds space
14-
cipher += ' '
15-
return cipher
12+
result += ch
13+
return result
1614

17-
def decrypt(self, message):
18-
decipher = ''
19-
for letter in message.upper():
20-
# checks for space
21-
if(letter != ' '):
22-
num = chr(((ord(letter) - ord('A') - 13 + 26) % 26) + ord('A'))
23-
decipher += num
15+
def decrypt(self, message: str) -> str:
16+
result = ''
17+
for ch in message.upper():
18+
if ch.isalpha():
19+
decoded = chr(((ord(ch) - ord('A') - 13 + 26) % 26) + ord('A'))
20+
result += decoded
2421
else:
25-
# adds space
26-
decipher += ' '
27-
return decipher
22+
result += ch
23+
return result

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="decrypto", # This is the name of the package
8-
version="1.0.5", # The initial release version
8+
version="1.0.6", # The initial release version
99
author="Prajjwal Pathak", # Full name of the author
1010
description="Light Weight python package for encrption/decryption",
1111
long_description=long_description, # Long description read from the the readme file

0 commit comments

Comments
 (0)