>>> hill_cipher = HillCipher(np.array([[2, 5], [1, 6]])) >>> hill_cipher.encrypt('testing hill cipher') 'WHXYJOLM9C6XT085LL' >>> hill_cipher.encrypt('hello') '85FF00'
(self, text: str)
| 118 | return "".join(chars) |
| 119 | |
| 120 | def encrypt(self, text: str) -> str: |
| 121 | """ |
| 122 | >>> hill_cipher = HillCipher(np.array([[2, 5], [1, 6]])) |
| 123 | >>> hill_cipher.encrypt('testing hill cipher') |
| 124 | 'WHXYJOLM9C6XT085LL' |
| 125 | >>> hill_cipher.encrypt('hello') |
| 126 | '85FF00' |
| 127 | """ |
| 128 | text = self.process_text(text.upper()) |
| 129 | encrypted = "" |
| 130 | |
| 131 | for i in range(0, len(text) - self.break_key + 1, self.break_key): |
| 132 | batch = text[i : i + self.break_key] |
| 133 | vec = [self.replace_letters(char) for char in batch] |
| 134 | batch_vec = np.array([vec]).T |
| 135 | batch_encrypted = self.modulus(self.encrypt_key.dot(batch_vec)).T.tolist()[ |
| 136 | 0 |
| 137 | ] |
| 138 | encrypted_batch = "".join( |
| 139 | self.replace_digits(num) for num in batch_encrypted |
| 140 | ) |
| 141 | encrypted += encrypted_batch |
| 142 | |
| 143 | return encrypted |
| 144 | |
| 145 | def make_decrypt_key(self) -> np.ndarray: |
| 146 | """ |
no test coverage detected