From a1e563a0988739508b2fa4947bf26f77eb31c4e7 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Tue, 26 Nov 2024 14:09:06 +0700 Subject: [PATCH] Create zero_knowledge_proof.py --- .../src/cryptography/zero_knowledge_proof.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 QuantumNexusProtocol/src/cryptography/zero_knowledge_proof.py diff --git a/QuantumNexusProtocol/src/cryptography/zero_knowledge_proof.py b/QuantumNexusProtocol/src/cryptography/zero_knowledge_proof.py new file mode 100644 index 000000000..533a3dc5b --- /dev/null +++ b/QuantumNexusProtocol/src/cryptography/zero_knowledge_proof.py @@ -0,0 +1,25 @@ +from hashlib import sha256 +import random + +class ZeroKnowledgeProof: + def __init__(self, secret): + self.secret = secret + + def commit(self): + self.random_value = random.randint(1, 100) + self.commitment = sha256(f"{self.secret}{self.random_value}".encode()).hexdigest() + return self.commitment + + def verify(self, challenge, response): + return sha256(f"{self.secret}{response}".encode()).hexdigest() == challenge + +# Example usage +if __name__ == "__main__": + secret = "my_secret" + zk_proof = ZeroKnowledgeProof(secret) + commitment = zk_proof.commit() + print(f"Commitment: {commitment}") + challenge = commitment # In a real scenario, this would be sent to the verifier + response = zk_proof.random_value # The prover sends back the random value + is_valid = zk_proof.verify(challenge, response) + print(f"Verification: {is_valid}")