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

Method generate_shared_key

ciphers/diffie_hellman.py:236–241  ·  view source on GitHub ↗
(self, other_key_str: str)

Source from the content-addressed store, hash-verified

234 )
235
236 def generate_shared_key(self, other_key_str: str) -> str:
237 other_key = int(other_key_str, base=16)
238 if not self.is_valid_public_key(other_key):
239 raise ValueError("Invalid public key")
240 shared_key = pow(other_key, self.__private_key, self.prime)
241 return sha256(str(shared_key).encode()).hexdigest()
242
243 @staticmethod
244 def is_valid_public_key_static(remote_public_key_str: int, prime: int) -> bool:

Callers

nothing calls this directly

Calls 2

is_valid_public_keyMethod · 0.95
encodeMethod · 0.45

Tested by

no test coverage detected