Skip to content

Commit e04c06c

Browse files
committed
minor fixes NTRU + added 2 more examples
1 parent 2546abc commit e04c06c

4 files changed

Lines changed: 431 additions & 183 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ contains solved exercises from *Introduction to Cryptography with Coding Theory*
5858
Tengely, Sz. — Example values used in this notebook are based on:
5959
[https://shrek.unideb.hu/~tengely/crypto/section-8.html](https://shrek.unideb.hu/~tengely/crypto/section-8.html))
6060

61+
- **Applied Cryptanalysis: Breaking Ciphers in the Real World**
62+
Mark Stamp, Richard M. Low — Wiley-IEEE Press, 2007.
63+
Chapter 6.7

lattice_methods/ntru.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from sympy import Poly, symbols, invert, ZZ, gcd, GF
1+
from sympy import Poly, symbols, invert, ZZ, gcd, GF, isprime
22
import numpy as np
33

44
x = symbols('x')
@@ -7,7 +7,12 @@
77
def invert_poly(polynomial_f, N, q):
88

99
#f = Poly(f_coeffs, x, domain=GF(q))
10-
mod_poly = Poly(x**N - 1, x, domain=GF(q))
10+
if(isprime(q)):
11+
mod_poly = Poly(x**N - 1, x, domain=GF(q))
12+
else:
13+
mod_poly = Poly(x ** N - 1, x, domain=ZZ).trunc(q)
14+
15+
polynomial_f = polynomial_f.set_domain(mod_poly.domain)
1116

1217
if gcd(polynomial_f, mod_poly).degree() != 0:
1318
return None
@@ -70,8 +75,11 @@ def ntru_generate_keys(N : int, p: int, q : int, polynomial_g : Poly, polynomial
7075
print("ERROR SMTH WRONG WITH p, q ")
7176
return
7277

78+
if(isprime(q)):
79+
poly_f_over_q = Poly(polynomial_f, x, domain=GF(q))
80+
else:
81+
poly_f_over_q = Poly(polynomial_f, x, domain=ZZ).trunc(q)
7382

74-
poly_f_over_q = Poly(polynomial_f, x, domain=GF(q))
7583
poly_f_over_p = Poly(polynomial_f, x, domain=GF(p))
7684

7785
Fp = invert_poly(poly_f_over_p, N, p)

0 commit comments

Comments
 (0)