Image for post
Image for post

Saying Goodbye to Napier’s Logs, and Hello To Elliptic Curves

A Bluffer’s Guide to converting discrete log problems into elliptic curve ones — it’s all about point adding and point multiplying

The Problem With Discrete Log Public Key

A discrete log problem

Image for post
Image for post

Elliptic Curve conversion

Coding

from secp256k1 import curve,scalar_mult,point_add
import random
print("Basepoint:\t", curve.g)a = random.randrange(1, curve.n)
aG = scalar_mult(a, curve.g)
b = random.randrange(1, curve.n)
bG = scalar_mult(b, curve.g)
x = random.randrange(1, curve.n)
xG = scalar_mult(x, curve.g)
y = random.randrange(1, curve.n)
yG = scalar_mult(y, curve.g)
k_a = point_add(scalar_mult(a,bG),scalar_mult(x,yG))
k_b = point_add(scalar_mult(b,aG),scalar_mult(y,xG))
print("\nAlice\'s secret key (a):\t", a)
print("Alice\'s public key:\t", aG)
print("\nBob\'s secret key (b):\t", b)
print("Bob\'s public key:\t", bG)
print("==========================")print("\nAlice\'s session secret key (x):\t", x)
print("Alice\'s session public key (xG):\t", xG)
print("\nBob\'s session secret key (y):\t", y)
print("Bob\'s session public key (yG):\t", yG)
print("\n==========================")
print("Shared Alice: abG+xyG: \t", (k_a[0]))
print("Shared Bob: baG+yxG: \t", (k_b[0]))
print("\n\n======Checking=========")
res=(a*b+x*y) % curve.n
res=scalar_mult(res, curve.g)print("\n(ab+xy)G \t", (res[0]))
Basepoint:   (55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424)Alice's secret key (a):  78415154667220249194754078918779762453056721468760306709254177946012547971141
Alice's public key: (99105229714153207673156985070193448370065961398966381789878734693715465172209, 110624902362275410698479512352481561725899665806375931075445037591290365955025)
Bob's secret key (b): 54561616670816631735058850292883594875584010720685581360400314879317249503108
Bob's public key: (113733186086318903761015041328623689948056538055691950119005093813948221458090, 107903521773313888319620134964700827003653413067839301511388495653810557170752)
==========================
Alice's session secret key (a): 76616834241497302450896773294650589907854814474518231453401510983257719855837
Alice's session public key: (24023634351058590672106977617527332391972478575360369234145700134892339616865, 100885767930009484943614670462898176000583227593861181472494539077386853703775)
Bob's session secret key (b): 71626425417421697561804712872377867220787646273545079991058910835106706879356
Bob's session public key: (5390516305312861583780866553511006508889363046035935478179214543880844748571, 108167309578588334529715598304887530494245835449345803403114120670801894220810)
==========================
Shared Alice: abG+xyG: 81373250065694576718644623930446201904803357573717034878729887795363849635428
Shared Bob: baG+yxG: 81373250065694576718644623930446201904803357573717034878729887795363849635428
======Checking=========(ab+xy)G 81373250065694576718644623930446201904803357573717034878729887795363849635428

References

Written by

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. EU Citizen. Auld Reekie native. Old World Breaker. New World Creator.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store