-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
QuantumNexusProtocol/src/cryptography/zero_knowledge_proof.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}") |