You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
1
# Understanding the parameters of Learning With Errors (LWE)
2
2
3
-
In this notebook I will briefly explain the Learning with Errors (LWE) method, which is a post-quantum public-key cryptography algorithm. We provide the mathematical background then detail our implementation based on Python 3 and `numpy`, and finally our experiments, whose objective is to understand how changing the parameters of the algorithm affects the expected result. Our experiments are based on the encryption and decryption of a single bit message of value `1`, which are executed ten thousand times for each configuration tested. Graphs are created to visualise the results.
3
+
In this report, I will briefly explain the Learning with Errors (LWE) method, which is a post-quantum public-key cryptography algorithm. We provide the mathematical background then detail our implementation based on Python 3 and `numpy`, and finally, our experiments, whose objective is to understand how changing the parameters of the algorithm affects the expected result. Our experiments are based on the encryption and decryption of a single bit message of value `1`, which are executed ten thousand times for each configuration tested. Graphs are created to visualize the results.
4
4
5
5
**Try live [here](https://mybinder.org/v2/gh/fredericoschardong/learning-with-errors-parameters/HEAD?filepath=Index.ipynb)**
6
6
7
-
##LWE Description
7
+
# LWE Description
8
8
9
9
LWE is a post-quantum publick-key algorithm, see [this presentation](https://summerschool-croatia.cs.ru.nl/2018/slides/Introduction%20to%20post-quantum%20cryptography%20and%20learning%20with%20errors.pdf) for more information and [the original paper](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.205.2622&rep=rep1&type=pdf). This method can be resumed to the computations described in this section. First, to create a public and private key:
 and  are the public key,  is the private key and  is the random error, and . The matrixes  have dimension , that is, they are single column, because in this report we implement a single-bit encryption and decryption.
13
+
 and  are the public keys,  is the private key and  is the random error, and . The matrixes  have dimension , that is, they are single column because in this report we implement single-bit encryption and decryption.
14
14
15
15
To encrypt a single-bit message  using the public key  we obtain the encrypted message composed of  with:
16
16
@@ -24,12 +24,12 @@ Where , where LWE is implemented to encrypt and decrypt a single bit of value `1`. All parameters required by the algorithm are passed as parameters for this function. They are:
30
30
+`n` and `m`, where `n` is the number of rows of the single column matrixes , and `m` is the modulo for all the operations
31
31
+`err` sets the largest value of the interval ![[1,err] \in \mathbb{Z}](https://render.githubusercontent.com/render/math?math=%5Cdisplaystyle+%5B1%2Cerr%5D+%5Cin+%5Cmathbb%7BZ%7D), from which error values are randomly drawn and then added to the result of , as described above
32
-
+`sample` sets the number of samples drawn from the public key  to encrypt the bit-message `1`
32
+
+`sample` sets the number of samples drawn from the public key  to encrypt the single-bit message `1`
33
33
+`times` sets how many times the experiment is reproduced to find a statistically relevant result
34
34
35
35
The returned value is in the range ![[0,1] \in \mathbb{R}](https://render.githubusercontent.com/render/math?math=%5Cdisplaystyle+%5B0%2C1%5D+%5Cin+%5Cmathbb%7BR%7D) and represents how many experiments ran successfully, that is, correctly encrypted and decrypted the bit `1`.
@@ -62,11 +62,11 @@ def run(n = 20, m = 97, err = 4, sample = 5, times = 10000):
62
62
return np.sum(((v - s * u) % m) > m /2) / times
63
63
```
64
64
65
-
##Experiments
65
+
# Experiments
66
66
67
67
Having detailed the mathematical background and how our implementation of LWE works, we now proceed to perform some experiments and discuss their results.
68
68
69
-
###1. Exploring how `n` affects the result
69
+
## 1. Exploring how `n` affects the result
70
70
71
71
72
72
```python
@@ -81,7 +81,7 @@ plt.show()
81
81
82
82
Increasing `n` doesn't affect the correctness of the encryption and decryption processes.
83
83
84
-
###2. Exploring how `err` affects the result
84
+
## 2. Exploring how `err` affects the result
85
85
86
86
87
87
```python
@@ -94,7 +94,7 @@ plt.show()
94
94

95
95
96
96
97
-
Apparently running LWE with the error range uper bound greater than roughly 10% of the modulo `m` affects the correctness of the output. Next, we try a prime modulo of about 10x the current to verify if the 10% threshold holds.
97
+
Apparently running LWE with the error range upper bound greater than roughly 10% of the modulo `m` affects the correctness of the output. Next, we try a prime modulo of about 10x the current to verify if the 10% threshold holds.
98
98
99
99
100
100
```python
@@ -128,7 +128,7 @@ plt.show()
128
128

129
129
130
130
131
-
Same behaviour. Now let's change the sampling size.
131
+
Same behavior. Now let's change the sampling size.
132
132
133
133
134
134
```python
@@ -150,7 +150,7 @@ plt.show()
150
150
151
151
152
152
Increasing the sample size has an impact! Apparently..
153
-
Next, we try with modulo `m = 997` and double the sample on each test to see if the behaviour continues.
153
+
Next, we try with modulo `m = 997` and double the sample on each test to see if the behavior continues.
154
154
155
155
156
156
```python
@@ -171,9 +171,9 @@ plt.show()
171
171

172
172
173
173
174
-
Empircally testing LWE the parameters seem to have to respect the ratio of  to correctly encrypt and decrypt.
174
+
Empircaly testing LWE the parameters seem to have to respect the ratio of  to correctly encrypt and decrypt.
175
175
176
-
Let's put this claim to the test. First we calculate all the prime numbers in the range ![[101,100000]](https://render.githubusercontent.com/render/math?math=%5Cdisplaystyle+%5B101%2C100000%5D) and select 1 for every 100 primes in the list. Then, for all these primes we select the number of samples at random (limiting at 1% of each prime) and calculate the uper bound value for the error range following the formula . Next, we run the LWE algorithm with the aforementioned parameters and plot the result. If our empirically found relation holds, then we shall see no point off the `1.0` value in the y axis.
176
+
Let's put this claim to the test. First, we calculate all the prime numbers in the range ![[101,100000]](https://render.githubusercontent.com/render/math?math=%5Cdisplaystyle+%5B101%2C100000%5D) and select 1 for every 100 primes in the list. Then, for all these primes we select the number of samples at random (limiting at 1% of each prime) and calculate the upper bound value for the error range following the formula . Next, we run the LWE algorithm with the aforementioned parameters and plot the result. If our empirically found relation holds, then we shall see no point off the `1.0` value in the y axis.
0 commit comments