Question: Question 4 . Alice sends a reply to Bob, encrypted as e 2 in the data file, but Bob's public key is not as well
Question Alice sends a reply to Bob, encrypted as e in the data file, but
Bob's public key is not as well configured as Alice's public key. We will play
the role of Eve, and break Bob's key. First, load Bob's public key into memory.
This will clear Alice's public key make sure you have the right key loaded
into the memory! Create the NTRU lattice matrix via NTRUmatrix
and then reduce it via LLL:
####################### FUNCTIONS #######################
### You can safely run this entire block at any point ###
### until you see the next block begin below. ###
def TddN:
Returns a random ternary polynomial in ZZz with:
d coefficients that equal
d coefficients that equal
if d d N:
raiseValueErrord d cannot exceed N
R PolynomialRingZZ
S SetrangeN
pos Ssubsetssizedrandomelement
S S pos
neg Ssubsetssizedrandomelement
v for i in rangeN
for i in pos:
vi
for i in neg:
vi
return Rv
def centerliftf:
R PolynomialRingZZ
P fparentbaseringcardinality
return R modt Pliftcentered for t in f
def encodes:
Encode the message ASCII string s as a polynomial mx in Rp
Uses environment variables p and N
s strs
k Nlogp
if lens k:
raiseValueError "String too long. Max length in Rp is strfloork
t sumordsii for i in rangelens
return Rptdigitsbasep
def decodem:
Decode the polynomial mx in Rp
mc listm
# Remember, mci belongs to GFp Lift to integers!
c sumIntegermcipi for i in rangelenmc
v join chrx for x in Integercdigitsbase
return v
def circulantmatrixa:
Returns the matrix whose ROWS are the rotations of the vector a:
a a an
an a an
a a a
n lena
R rangen
return matrix ajk n for j in R for k in R
def NTRUmatrixh:
Returns the NTRU lattice matrix associated to the public key
Npqd and hy in Rq in row form.
This matrix is in ROW form, the N x N block matrix:
I H
qI
where H is the circulant matrix generated by the coefficients of h
as a vector.
hv listcenterlifth
H circulantmatrixhv
I identitymatrixZZ N
O zeromatrixZZ N
return blockmatrixI HO qI
### End of functions block ###
###################################################
#################### PROBLEMS onwards ####################
#################### Alice's public key ####################
p
q
N
d
R PolynomialRingZZ
Sp PolynomialRingGFp
Rp SpquotientYN
Sq PolynomialRingGFq
Rq SqquotientZN
h zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
