ciphers.shuffled_shift_cipher

Classes

ShuffledShiftCipher

This algorithm uses the Caesar Cipher algorithm but removes the option to

Functions

test_end_to_end(→ str)

Module Contents

class ciphers.shuffled_shift_cipher.ShuffledShiftCipher(passcode: str | None = None)

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. digits from 0 to 9

Using unique characters from the passcode, the normal list of characters, that can be allowed in the plaintext, is pivoted and shuffled. Refer to docstring of __make_key_list() to learn more about the shuffling.

Then, using the passcode, a number is calculated which is used to encrypt the plaintext message with the normal shift cipher method, only in this case, the reference, to look back at while decrypting, is shuffled.

Each cipher object can possess an optional argument as passcode, without which a new passcode is generated for that object automatically. cip1 = ShuffledShiftCipher(‘d4usr9TWxw9wMD’) cip2 = ShuffledShiftCipher()

__make_key_list() list[str]

Shuffles the ordered character choices by pivoting at breakpoints Breakpoints are the set of characters in the passcode

eg:

if, ABCDEFGHIJKLMNOPQRSTUVWXYZ are the possible characters and CAMERA is the passcode then, breakpoints = [A,C,E,M,R] # sorted set of characters from passcode shuffled parts: [A,CB,ED,MLKJIHGF,RQPON,ZYXWVUTS] shuffled __key_list : ACBEDMLKJIHGFRQPONZYXWVUTS

Shuffling only 26 letters of the english alphabet can generate 26! combinations for the shuffled list. In the program we consider, a set of 97 characters (including letters, digits, punctuation and whitespaces), thereby creating a possibility of 97! combinations (which is a 152 digit number in itself), thus diminishing the possibility of a brute force approach. Moreover, shift keys even introduce a multiple of 26 for a brute force approach for each of the already 97! combinations.

__make_shift_key() int

sum() of the mutated list of ascii values of all characters where the mutated list is the one returned by __neg_pos()

__neg_pos(iterlist: list[int]) list[int]

Mutates the list by changing the sign of each alternate element

Parameters:

iterlist – takes a list iterable

Returns:

the mutated list

__passcode_creator() list[str]

Creates a random password from the selection buffer of 1. uppercase letters of the English alphabet 2. lowercase letters of the English alphabet 3. digits from 0 to 9

Return type:

list

Returns:

a password of a random length between 10 to 20

__str__() str
Returns:

passcode of the cipher object

decrypt(encoded_message: str) str

Performs shifting of the encoded_message w.r.t. the shuffled __key_list to create the decoded_message

>>> ssc = ShuffledShiftCipher('4PYIXyqeQZr44')
>>> ssc.decrypt("d>**-1z6&'5z'5z:z+-='$'>=zp:>5:#z<'.&>#")
'Hello, this is a modified Caesar cipher'
encrypt(plaintext: str) str

Performs shifting of the plaintext w.r.t. the shuffled __key_list to create the encoded_message

>>> ssc = ShuffledShiftCipher('4PYIXyqeQZr44')
>>> ssc.encrypt('Hello, this is a modified Caesar cipher')
"d>**-1z6&'5z'5z:z+-='$'>=zp:>5:#z<'.&>#"
__key_list
__passcode
__shift_key
ciphers.shuffled_shift_cipher.test_end_to_end(msg: str = 'Hello, this is a modified Caesar cipher') str
>>> test_end_to_end()
'Hello, this is a modified Caesar cipher'