>>> hill_cipher = HillCipher(np.array([[2, 5], [1, 6]])) >>> hill_cipher.check_determinant()
(self)
| 84 | return self.key_string[int(num)] |
| 85 | |
| 86 | def check_determinant(self) -> None: |
| 87 | """ |
| 88 | >>> hill_cipher = HillCipher(np.array([[2, 5], [1, 6]])) |
| 89 | >>> hill_cipher.check_determinant() |
| 90 | """ |
| 91 | det = round(np.linalg.det(self.encrypt_key)) |
| 92 | |
| 93 | if det < 0: |
| 94 | det = det % len(self.key_string) |
| 95 | |
| 96 | req_l = len(self.key_string) |
| 97 | if greatest_common_divisor(det, len(self.key_string)) != 1: |
| 98 | msg = ( |
| 99 | f"determinant modular {req_l} of encryption key({det}) " |
| 100 | f"is not co prime w.r.t {req_l}.\nTry another key." |
| 101 | ) |
| 102 | raise ValueError(msg) |
| 103 | |
| 104 | def process_text(self, text: str) -> str: |
| 105 | """ |
no test coverage detected