MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / decrypt_message

Function decrypt_message

ciphers/affine_cipher.py:56–74  ·  view source on GitHub ↗

>>> decrypt_message(4545, 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF' ... '{xIp~{HL}Gi') 'The affine cipher is a type of monoalphabetic substitution cipher.'

(key: int, message: str)

Source from the content-addressed store, hash-verified

54
55
56def decrypt_message(key: int, message: str) -> str:
57 """
58 >>> decrypt_message(4545, 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF'
59 ... '{xIp~{HL}Gi')
60 'The affine cipher is a type of monoalphabetic substitution cipher.'
61 """
62 key_a, key_b = divmod(key, len(SYMBOLS))
63 check_keys(key_a, key_b, "decrypt")
64 plain_text = ""
65 mod_inverse_of_key_a = cryptomath.find_mod_inverse(key_a, len(SYMBOLS))
66 for symbol in message:
67 if symbol in SYMBOLS:
68 sym_index = SYMBOLS.find(symbol)
69 plain_text += SYMBOLS[
70 (sym_index - key_b) * mod_inverse_of_key_a % len(SYMBOLS)
71 ]
72 else:
73 plain_text += symbol
74 return plain_text
75
76
77def get_random_key() -> int:

Callers 1

mainFunction · 0.70

Calls 2

check_keysFunction · 0.85
findMethod · 0.45

Tested by

no test coverage detected