import hashlib;
import passlib.hash;
import sys;

# First ZKP algorithm using sha256 to understand how the algorithm works


#Verifier does not know the age
age_actual = 19
age_to_prove = 18

# This is seed is a random value generated by a Third Party, to ensure security
seed = "1234"
print "\n"

#This is a digital signature proof by Truted Entity
proof = hashlib.sha256(seed)
print "Proof is " +  proof.hexdigest()

#Proof and Encrypted have same values for the moment
encrypted_age = hashlib.sha256(seed)
print "Encrypted Age (initialized with seed) is " +  encrypted_age.hexdigest()
print "\n"

#If b < a, we don't loop, so we don't hash
a = 1
b = 1 + age_actual - age_to_prove
for i in range(a, b):
    proof = hashlib.sha256(proof.digest())

print "New Proof is " +  proof.hexdigest()

#Prover hashes age_actual times his age to secure it
c = 1
d = age_actual + 1
for i in range(c, d):
    encrypted_age = hashlib.sha256(encrypted_age.digest())
print "New Encrypted Age is " +  encrypted_age.hexdigest()
print "\n"


#Verified Age will be Hashed age_to_prove times
verified_age = proof
for i in range(0, age_to_prove):
    verified_age = hashlib.sha256(verified_age.digest())

print "Verified Age is " +  verified_age.hexdigest()



print "Peggy's Age:\t\t", age_actual
print "Age to prove:\t\t", age_to_prove

print "...."


print "Proof:\t\t", proof.hexdigest()
print "Encrypted Age:\t", encrypted_age.hexdigest()
print "Verified Age:\t", verified_age.hexdigest()
print "\n"

#We check if Encrypted Age (By Prover) and Verified_Age (By Verifier)
if (encrypted_age.hexdigest() == verified_age.hexdigest()):
	print "You have proven your age ... please come in"
else:
	print "You have not proven you age!"
