Photo by Chris Liverani on Unsplash

Homomorphic Encryption with Learning With Errors (LWE)

We secure data in its transit, and at its rest, but what happens in process? Well, we are perhaps moving into a world which will protect data at every point of its journey. This will be a world of homomorphic encryption.

Learning With Errors (LWE) is a quantum robust method of cryptography. Initially we create a secret value (s) and which is our private key. We then create a public key which is based on random numbers (A), and then generate another set of numbers (B) which is based on A, s and random errors e. In this case we will show how a 4-bit value can be encrypted. In this case we will convert an integer to a 4-bit value, and then cipher each of the bits. This is achieved by generating a public key, and then sampling the public key for each of the bits.

First we select a random series of values for our public key (A). For example, let’s select 20 random values from 0 to 100:

Next we add create a list (B) and were the elements are Bi=Ais+ei(modq), and where s is a secret value, and e is a list of small random values (the error values). If we take a prime number (q) of 97, and an error array (e) of:

we generate a list (B) of:

The A and B list will be our public key, and s will be our secret key. We can now distribute A and B to anyone who wants to encrypt a message for us (but keep s secret). To encrypt we take samples from the A and B lists, and take a message bit (M), and then calculate two values:

The encrypted message is (u,v ). To decrypt, we calculate:

If Dec is less than q2 , the message is a zero, else it is a 1.

For homomophic encryption, we can perform a single-bit adder function by generating (u,v) for each of the bits and then performing (for the two values for bit0 - v1_0, u1_0,v2_0 and u2_0):

With multiple bits, we basically take our value and then convert into bits. Next we cipher each bit by taking a random sample from the public key. A sample run where we add 4 plus 1 is [here]:

The following is an outline of the code [here]:

An outline is here:

With the increasing requirement to protect data, we will see a rise in its protection within processes.

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