Question: Question 2 . Load Alice's public and private key data into the memory. The values of R , R p , R q are all
Question Load Alice's public and private key data into the memory. The
values of are all defined; has variable in Sage, has variable
and has variable You can send a polynomial from R like Alice's
given by in the data file, to its version in via the command Verify
that Alice's public key is correctly set up that is that in
by running in Sage, and seeing that you get the same value as
Notice how your answers will have the variable, to indicate that Sage
is thinking of them as polynomials, whose coefficients are modulo
####################### 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 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
