John Napier’s “Signature” in 12 lines of Python

--

My university campus is in the home of John Napier, and my city (Edinburgh) and university thus have a strong linkage to logarithms. One of the great things about logs is that they are now used in computer security — in the form of discrete logs. For this we have the difficulty of finding the inverse log when we use large numbers. For example — if we use very large numbers — it is extremely difficult to find x, even if we know g and v:

v=g^x

In order to make the maths work for other operations, we add in the modulo — the remainder of an integer divide — of a prime number (mod p):

v=g^x (mod p)

So, let’s see if we can sign for some data, and where we create a value which checks that we have signing it with a secret, and where we should a public value for verification. This is know as public key signing, and where we sign our data with a private key (a secret value) and everyone else proves it with our public key. In the following we will create a simple ElGamal signer for a message, and try to do it in just 12 lines of Python code.

With ElGamal signing, we create a secret signing exponent (s) and then a signing exponent of:

To sign a document (D), we create an ephemeral key (e) — note that this value will not be needed to be sent, but…

--

--

Prof Bill Buchanan OBE FRSE
ASecuritySite: When Bob Met Alice

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. Based in Edinburgh. Old World Breaker. New World Creator. Building trust.