MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / decrypt

Method decrypt

ciphers/shuffled_shift_cipher.py:127–147  ·  view source on GitHub ↗

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'

(self, encoded_message: str)

Source from the content-addressed store, hash-verified

125 return num if num > 0 else len(self.__passcode)
126
127 def decrypt(self, encoded_message: str) -> str:
128 """
129 Performs shifting of the encoded_message w.r.t. the shuffled __key_list
130 to create the decoded_message
131
132 >>> ssc = ShuffledShiftCipher('4PYIXyqeQZr44')
133 >>> ssc.decrypt("d>**-1z6&'5z'5z:z+-='$'>=zp:>5:#z<'.&>#")
134 'Hello, this is a modified Caesar cipher'
135
136 """
137 decoded_message = ""
138
139 # decoding shift like Caesar cipher algorithm implementing negative shift or
140 # reverse shift or left shift
141 for i in encoded_message:
142 position = self.__key_list.index(i)
143 decoded_message += self.__key_list[
144 (position - self.__shift_key) % -len(self.__key_list)
145 ]
146
147 return decoded_message
148
149 def encrypt(self, plaintext: str) -> str:
150 """

Callers 1

test_end_to_endFunction · 0.95

Calls

no outgoing calls

Tested by 1

test_end_to_endFunction · 0.76