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

Function encrypt_message

ciphers/affine_cipher.py:38–53  ·  view source on GitHub ↗

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

(key: int, message: str)

Source from the content-addressed store, hash-verified

36
37
38def encrypt_message(key: int, message: str) -> str:
39 """
40 >>> encrypt_message(4545, 'The affine cipher is a type of monoalphabetic '
41 ... 'substitution cipher.')
42 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF{xIp~{HL}Gi'
43 """
44 key_a, key_b = divmod(key, len(SYMBOLS))
45 check_keys(key_a, key_b, "encrypt")
46 cipher_text = ""
47 for symbol in message:
48 if symbol in SYMBOLS:
49 sym_index = SYMBOLS.find(symbol)
50 cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(SYMBOLS)]
51 else:
52 cipher_text += symbol
53 return cipher_text
54
55
56def decrypt_message(key: int, message: str) -> str:

Callers 1

mainFunction · 0.70

Calls 2

check_keysFunction · 0.85
findMethod · 0.45

Tested by

no test coverage detected