Skip to content

Commit 8c08771

Browse files
authored
Update shuffled_shift_cipher.py
1 parent f1b0353 commit 8c08771

1 file changed

Lines changed: 17 additions & 26 deletions

File tree

ciphers/shuffled_shift_cipher.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,21 @@
55

66

77
class ShuffledShiftCipher:
8-
"""
9-
This algorithm uses the Caesar Cipher algorithm but removes the option to
10-
use brute force to decrypt the message.
11-
12-
The passcode is a random password from the selection buffer of
13-
1. uppercase letters of the English alphabet
14-
2. lowercase letters of the English alphabet
15-
3. digits from 0 to 9
16-
17-
Using unique characters from the passcode, the normal list of characters,
18-
that can be allowed in the plaintext, is pivoted and shuffled. Refer to docstring
19-
of __make_key_list() to learn more about the shuffling.
20-
21-
Then, using the passcode, a number is calculated which is used to encrypt the
22-
plaintext message with the normal shift cipher method, only in this case, the
23-
reference, to look back at while decrypting, is shuffled.
24-
25-
Each cipher object can possess an optional argument as passcode, without which a
26-
new passcode is generated for that object automatically.
27-
cip1 = ShuffledShiftCipher('d4usr9TWxw9wMD')
28-
cip2 = ShuffledShiftCipher()
29-
8+
"""
309
Enhanced Caesar Cipher with shuffled character set for stronger encryption.
3110
Uses a passcode to generate a unique shuffled key list and shift key.
11+
12+
The passcode is a random password from the selection buffer of:
13+
1. Uppercase letters of the English alphabet
14+
2. Lowercase letters of the English alphabet
15+
3. Digits from 0 to 9
16+
17+
Each cipher object can possess an optional argument as passcode, without which a
18+
new passcode is generated for that object automatically.
19+
20+
Example:
21+
>>> cip1 = ShuffledShiftCipher('d4usr9TWxw9wMD')
22+
>>> cip2 = ShuffledShiftCipher()
3223
"""
3324

3425
def __init__(self, passcode: str | None = None) -> None:
@@ -61,8 +52,8 @@ def __make_key_list(self) -> list[str]:
6152
# Get printable characters except rare whitespace
6253
key_options = string.printable.strip("\r\x0b\x0c")
6354
breakpoints = sorted(set(self.__passcode))
64-
shuffled: list[str] = [] # Explicit type annotation
65-
temp: list[str] = [] # Explicit type annotation
55+
shuffled: list[str] = []
56+
temp: list[str] = []
6657

6758
for char in key_options:
6859
temp.append(char)
@@ -80,7 +71,7 @@ def __make_shift_key(self) -> int:
8071

8172
def encrypt(self, plaintext: str) -> str:
8273
"""Encrypt plaintext using shuffled shift cipher."""
83-
encoded: list[str] = [] # Explicit type annotation
74+
encoded: list[str] = []
8475
key_len = len(self.__key_list)
8576

8677
for char in plaintext:
@@ -92,7 +83,7 @@ def encrypt(self, plaintext: str) -> str:
9283

9384
def decrypt(self, encoded_message: str) -> str:
9485
"""Decrypt message using shuffled shift cipher."""
95-
decoded: list[str] = [] # Explicit type annotation
86+
decoded: list[str] = []
9687
key_len = len(self.__key_list)
9788

9889
for char in encoded_message:

0 commit comments

Comments
 (0)