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
)
| 122 | |
| 123 | |
| 124 | def 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 | |
| 169 | def decrypt_message( |
no test coverage detected