Beispiel #1
0
	def size_modp(self, p):
		
		#If we already know this size, return it from the saved list.
		if len(self.sizes)>0:
			for n in range(len(self.sizes)):
				if self.sizes[n][1]==p:
					return self.sizes[n][0]

		#Computes the size mod 2
		N = 1
		if p==2:
			for x in range(2):
				for y in range(2):
					if (y**2-((x**3) +self.coef[0]*x +self.coef[1]))%2 ==0:
						N=N+1
			self.sizes.append([N,p])
			return N

		#If we don't know the size of E mod p where p is odd, then we use Euler's Criterion to check
		#if x^3+ax+b is a square mod p or not.
		for x in range(p):
			X=(x**3) +self.coef[0]*x +self.coef[1]
			L=MLib.euler_crit(X,p)
			if  L== 1 :
				N=N+2
			if L==0:
				N=N+2
			if N > p+3 +2*int(p**(0.5)):
					break
		self.sizes.append([N,p])
		print(p,N," : ", N-(p+1), 2*(p**(0.5))) #For visual progress reports while running.
		return N
Beispiel #2
0
#x^2-y^2=4 where (x,y) on the Pell Conic corresponds to ((x-y)/2,(x+y)/2)
#when we mod by an odd N.
#We can then use the ideas of the typical RSA Encryption to encrypt 
#a point on a Pell Conic and use knowledge of the conic and of the
#prime factorization of N=pq to find a private key quickly via the
#Chinese Remainder Theorem. This is what this program does


#Setup: Specify the discriminant of the Pell Conic. Specify N=pq,
#N is public and p,q are private. Choose a code ie an integer
#e to encode the points. Use the Chinese Remainder Theoerem to
#find the inverse k of e for this curve.

print('--Initialize the Curve--')
print('-The curve will be the Pell Conic x^2-dy^2=4 mod N=pq')
d = MLib.fund_disc(int(input('Input the Discriminant d:')))


p = int(input('Input the first prime factor of N: '))
while MLib.isprime(p)==0:
	p = int(input('That was not prime, please input a prime: '))



q = int(input('Input the second prime factor of N: '))
while MLib.isprime(q)==0:
	q = int(input('That was not prime, please input a prime: '))
	while p==q:
		q = int(input('That number will not work, try another: '))
	
N=p*q