Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 515

Koyama-Maurer-Okamoto-Vanstone (KMOV)

RSA-like Encryption Based on Elliptic Curves

import numpy import itertools def ASCIIPad(Mess,Mod): K = [] for letter in Mess: K.append(ord(letter)) L = Mod.ndigits() l = len(K) y = ZZ(math.floor(L/3)) count = 0 padded = [] buffer = "" for numChar in K: numChar+=100 buffer+=str(numChar) count+=1 if count==y: padded.append(ZZ(buffer)) buffer = "" count = 0 if len(buffer)>0: padded.append(ZZ(buffer)) return padded def ASCIIDepad(Number): N = ""; n = Number.ndigits() % 3; if (n > 0): print("This is not a padded ASCII string\n"); else: L = [((Number - (Number % (1000^i)))/1000^i)%1000 - 100 for i in range(Number.ndigits()/3)]; for i in range(Number.ndigits()/3): N = chr(L[i]) + N; return(N); def ECRAdd(Point1,Point2,Group): a = Group[0] b = Group[1] p = Group[2] if Point1!=[]: x1 = Point1[0] y1 = Point1[1] if Point2!=[]: x2 = Point2[0] y2 = Point2[1] if ZZ(mod(4*a^3 + 27*b^2, p)) == 0: print ("This is not an ellitpic curve") elif Point1!=[] and ZZ(mod(y1^2, p)) != ZZ(mod(x1^3 + a*x1 + b,p)): print ("Point 1 is not on the elliptic curve.") elif Point2!=[] and ZZ(mod(y2^2, p)) != ZZ(mod(x2^3 + a*x2 + b,p)): print ("Point 2 is not on the elliptic curve.") else: if Point1==[]: R=Point2 elif Point2=={}: R=Point1 else: if x1==x2 and 0==ZZ(mod(y1+y2,p)): R=[] elif x1==x2 and y1==y2: R=ECRDouble(Point1,Group) if R==True: return(True) else: g=gcd(x1-x2,p) if (g>1): print ("factor is {0}".format(g)) return(True) s=ZZ(mod((y1-y2)/(x1-x2),p)) x=ZZ(mod(s^2-(x1+x2),p)) y=ZZ(mod(s*(x1-x)-y1,p)) R=[x,y] return R
def ECRDouble(Point,Group): a = Group[0] b = Group[1] p = Group[2] if Point!=[]: x1 = Point[0] y1 = Point[1] if ZZ(mod(4*a^3 + 27*b^2, p)) == 0: print ("This is not an ellptic curve") elif Point!= [] and ZZ(mod(y1^2,p))!= ZZ(mod(x1^3+a*x1+b,p)): print ("point to double not on elliptic curve") elif y1==0: R=[] else: g = gcd(y1,p) if g>1: print ("Factor is {0}".format(g)) return True s = ZZ(mod((3*x1^2+a)/(2*y1),p)) x = ZZ(mod(s^2-(x1+x1),p)) y = ZZ(mod(s*(x1-x)-y1,p)) R = [x,y] else: R=[] return R
def ECRTimes(Point,scalar,Group): ECIDENTITY = [] if Point==ECIDENTITY or scalar ==0: return ECIDENTITY else: m = scalar pt = Point x = ECIDENTITY j=1 while j<(scalar +1): if m%2==0: m = m/2 else: m=(m-1)/2 x=ECRAdd(x,pt,Group) if x==True: return true if m==0: return x pt = ECRDouble(pt,Group) if pt==True: return true j+=1
def ECRInverse (Point, Group): if Point == []: return(Point) else: p = Group[2] x = Point[0] y = Point[1] return([x,(p - y) % p])
n=6917257498733996147938371874633328816556752630891230167602750050663225392713827472369791 s=10008345747001 t= 4117749622628666100756441055185740317505736625202292131017935879300104542402810720953433 print('Private Key:') print('t=', t) print('Public Key:') print('n=', n) print('s=', s)
Private Key: t= 4117749622628666100756441055185740317505736625202292131017935879300104542402810720953433 Public Key: n= 6917257498733996147938371874633328816556752630891230167602750050663225392713827472369791 s= 10008345747001
M="Information Security" m=ASCIIPad(M,n) print ('The padded ASCII version of the plaintext is:', m)
The padded ASCII version of the plaintext is: [173210202211214209197216205211210132183201199217214205216221]
b=(1-m[0]^3) %n E=[0,b,n] print ('The elliptic curve group is:', E)
The elliptic curve group is: [0, 3020530985299184291599609240714612842029478907414102977434017401106896368717353991604026, 6917257498733996147938371874633328816556752630891230167602750050663225392713827472369791]
pt=[m[0],1] c=ECRTimes(pt,s,E) print('The ciphertext is:', c)
The ciphertext is: [1835449135407271122180175106020375488710177408875137798012322720564309179236753357104986, 6746005215820619885607422385239986394759560144857805498142475098742794305531869234326693]
B=(c[1]^2-c[0]^3) %n ED=[0,B,n] ptd=ECRTimes(c,t,ED) ASCIIDepad(ptd[0])
'Information Security'