Created
October 13, 2018 02:20
-
-
Save SaifRehman/36a3b6579997fe54ac30fca2022d34c2 to your computer and use it in GitHub Desktop.
schnorr.py
This file contains hidden or 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
| import ed25519_python as curve | |
| import random | |
| import hashlib | |
| alicePrivateKey = curve.curve.mul(curve.curve.g,5) | |
| alicePrivateKey = curve.curve.compress(alicePrivateKey).encode('hex') | |
| m = "hello world" | |
| G = curve.curve.g | |
| alicePublicKeyOrignal = curve.curve.mul(G,int(alicePrivateKey,16)) | |
| alicePublicKey = curve.curve.compress(alicePublicKeyOrignal).encode('hex') | |
| r = random.randint(1, 2^50) | |
| ROrignal = curve.curve.mul(curve.curve.g,r) | |
| R = ROrignal[0] | |
| hash = hashlib.sha256(str(int(alicePublicKey,16)).encode('utf-8')+str(R).encode('utf-8')+m.encode('utf-8')).hexdigest() | |
| s = (int(hash,16) * int(alicePrivateKey,16)) + r | |
| s1 = curve.curve.mul(curve.curve.g,s) | |
| hash2 = hashlib.sha256(str(int(alicePublicKey,16)).encode('utf-8')+str(R).encode('utf-8')+m.encode('utf-8')).hexdigest() | |
| s3 = curve.curve.mul(alicePublicKeyOrignal,int(hash2,16)) | |
| s3 = curve.curve.add(ROrignal,s3) | |
| print (s1,s3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment