This algorithm uses the Caesar Cipher algorithm but removes the option to use brute force to decrypt the message. The passcode is a random password from the selection buffer of 1. uppercase letters of the English alphabet 2. lowercase letters of the English alphabet 3. digi
| 5 | |
| 6 | |
| 7 | 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 | """ |
| 30 | |
| 31 | def __init__(self, passcode: str | None = None) -> None: |
| 32 | """ |
| 33 | Initializes a cipher object with a passcode as it's entity |
| 34 | Note: No new passcode is generated if user provides a passcode |
| 35 | while creating the object |
| 36 | """ |
| 37 | self.__passcode = passcode or self.__passcode_creator() |
| 38 | self.__key_list = self.__make_key_list() |
| 39 | self.__shift_key = self.__make_shift_key() |
| 40 | |
| 41 | def __str__(self) -> str: |
| 42 | """ |
| 43 | :return: passcode of the cipher object |
| 44 | """ |
| 45 | return "".join(self.__passcode) |
| 46 | |
| 47 | def __neg_pos(self, iterlist: list[int]) -> list[int]: |
| 48 | """ |
| 49 | Mutates the list by changing the sign of each alternate element |
| 50 | |
| 51 | :param iterlist: takes a list iterable |
| 52 | :return: the mutated list |
| 53 | |
| 54 | """ |
| 55 | for i in range(1, len(iterlist), 2): |
| 56 | iterlist[i] *= -1 |
| 57 | return iterlist |
| 58 | |
| 59 | def __passcode_creator(self) -> list[str]: |
| 60 | """ |
| 61 | Creates a random password from the selection buffer of |
| 62 | 1. uppercase letters of the English alphabet |
| 63 | 2. lowercase letters of the English alphabet |
| 64 | 3. digits from 0 to 9 |
no outgoing calls