Question: Question 3 . Bob has sent Alice an encrypted message e ( x ) , given as e 1 in the data file. Load this
Question Bob has sent Alice an encrypted message given as e in
the data file. Load this value into memory, and decrypt it using Alice's private
key. You can use the centerlift function to compute the centered life from
or to so for example, once you compute in you can
run centerlift to get in its centered lift form in
Notice this will be a polynomial in Remember, you can find the inverse of
a polynomial in or via or Don't forget
that when you find the centered lift, your polynomial is now in R so you will
need to convert it to Rp via Rpa Finally, you can use the decode function
to decode your
####################### 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 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
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
