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

Method check_determinant

ciphers/hill_cipher.py:86–102  ·  view source on GitHub ↗

>>> hill_cipher = HillCipher(np.array([[2, 5], [1, 6]])) >>> hill_cipher.check_determinant()

(self)

Source from the content-addressed store, hash-verified

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 """

Callers 1

__init__Method · 0.95

Calls 1

greatest_common_divisorFunction · 0.90

Tested by

no test coverage detected