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

Method generate_shared_key_static

ciphers/diffie_hellman.py:252–261  ·  view source on GitHub ↗
(
        local_private_key_str: str, remote_public_key_str: str, group: int = 14
    )

Source from the content-addressed store, hash-verified

250
251 @staticmethod
252 def generate_shared_key_static(
253 local_private_key_str: str, remote_public_key_str: str, group: int = 14
254 ) -> str:
255 local_private_key = int(local_private_key_str, base=16)
256 remote_public_key = int(remote_public_key_str, base=16)
257 prime = primes[group]["prime"]
258 if not DiffieHellman.is_valid_public_key_static(remote_public_key, prime):
259 raise ValueError("Invalid public key")
260 shared_key = pow(remote_public_key, local_private_key, prime)
261 return sha256(str(shared_key).encode()).hexdigest()
262
263
264if __name__ == "__main__":

Callers

nothing calls this directly

Calls 2

encodeMethod · 0.45

Tested by

no test coverage detected