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

Function decrypt_message

ciphers/trifid_cipher.py:169–205  ·  view source on GitHub ↗

decrypt_message =============== Decrypts a trifid_cipher encrypted message. PARAMETERS ---------- * `message`: The message you want to decrypt. * `alphabet` (optional): The characters used for the cipher. * `period` (optional): The number of chara

(
    message: str, alphabet: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.", period: int = 5
)

Source from the content-addressed store, hash-verified

167
168
169def decrypt_message(
170 message: str, alphabet: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.", period: int = 5
171) -> str:
172 """
173 decrypt_message
174 ===============
175
176 Decrypts a trifid_cipher encrypted message.
177
178 PARAMETERS
179 ----------
180
181 * `message`: The message you want to decrypt.
182 * `alphabet` (optional): The characters used for the cipher.
183 * `period` (optional): The number of characters used in grouping when it
184 was encrypted.
185
186 >>> decrypt_message('BCDGBQY')
187 'IAMABOY'
188
189 Decrypting with your own alphabet and period
190
191 >>> decrypt_message('FMJFVOISSUFTFPUFEQQC','FELIXMARDSTBCGHJKNOPQUVWYZ+',5)
192 'AIDETOILECIELTAIDERA'
193 """
194 message, alphabet, character_to_number, number_to_character = __prepare(
195 message, alphabet
196 )
197
198 decrypted_numeric = []
199 for i in range(0, len(message), period):
200 a, b, c = __decrypt_part(message[i : i + period], character_to_number)
201
202 for j in range(len(a)):
203 decrypted_numeric.append(a[j] + b[j] + c[j])
204
205 return "".join(number_to_character[each] for each in decrypted_numeric)
206
207
208if __name__ == "__main__":

Callers 1

trifid_cipher.pyFile · 0.70

Calls 3

__prepareFunction · 0.85
__decrypt_partFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected