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

Function encrypt_message

ciphers/trifid_cipher.py:124–166  ·  view source on GitHub ↗

encrypt_message =============== Encrypts a message using the trifid_cipher. Any punctuatuion chars that would be used should be added to the alphabet. PARAMETERS ---------- * `message`: The message you want to encrypt. * `alphabet` (optional): The c

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

Source from the content-addressed store, hash-verified

122
123
124def encrypt_message(
125 message: str, alphabet: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.", period: int = 5
126) -> str:
127 """
128 encrypt_message
129 ===============
130
131 Encrypts a message using the trifid_cipher. Any punctuatuion chars that
132 would be used should be added to the alphabet.
133
134 PARAMETERS
135 ----------
136
137 * `message`: The message you want to encrypt.
138 * `alphabet` (optional): The characters to be used for the cipher .
139 * `period` (optional): The number of characters you want in a group whilst
140 encrypting.
141
142 >>> encrypt_message('I am a boy')
143 'BCDGBQY'
144
145 >>> encrypt_message(' ')
146 ''
147
148 >>> encrypt_message(' aide toi le c iel ta id era ',
149 ... 'FELIXMARDSTBCGHJKNOPQUVWYZ+',5)
150 'FMJFVOISSUFTFPUFEQQC'
151
152 """
153 message, alphabet, character_to_number, number_to_character = __prepare(
154 message, alphabet
155 )
156
157 encrypted_numeric = ""
158 for i in range(0, len(message) + 1, period):
159 encrypted_numeric += __encrypt_part(
160 message[i : i + period], character_to_number
161 )
162
163 encrypted = ""
164 for i in range(0, len(encrypted_numeric), 3):
165 encrypted += number_to_character[encrypted_numeric[i : i + 3]]
166 return encrypted
167
168
169def decrypt_message(

Callers 1

trifid_cipher.pyFile · 0.70

Calls 2

__prepareFunction · 0.85
__encrypt_partFunction · 0.85

Tested by

no test coverage detected