Skip to content

Instantly share code, notes, and snippets.

@alejandroave
Created September 13, 2012 12:18
generet keys
import random ##import mmodul random
p = 0
q = 0
n = 0
modul = 0
c = []
a = []
b = []
d = []
z = []
##funcion for comprobet if some numer is prime
def primo(x):
global n
i = 0
c = 0
while i < (x - 1):
i = i + 1
residuo = x % i
if residuo==0:
c=c+1
if c>=2:
print "no es primo: ",x
else:
if x==1:
print "es uno xD"
else:
print "EL numero si es primo ",x
n = n + 1
return x
while n < 2:
if n ==1 :
p = random.randint(1, 10)
a1 = primo(p)
else:
q = random.randint(1, 10)
b1 = primo(q)
si = 0
##funcion to comprobet if two numer is coprime
def gcd(en,e):
global si
global modul
modul = en % e
if modul == 0:
print "maximo factor de los numeros"
print "maximo factor = ",e
#if modul == 1:
# print "si son primos entre si: ",modul
else:
if modul == 1:
print "si son primos entre si"
si = 1
else:
if modul != 0:
en = e
e = modul
gcd(en,e)
##funcio to found ecuacion for eculides
def euclides(en,e):
x = en
y = e
modul = x % y
divi = x / y
print "resultado de la divicion",divi
print "sobrante ",modul
a.append(x)
b.append(y)
x = y
y = modul
c.append(divi)
d.append(modul)
if modul == 0:
print "termio"
print c
print modul
else:
euclides(x,y)
print "a= ",a
print "b = ",b
print "c = ",c
print "d= ",d
##codigo in general to found n,e,phi
while si < 1:
while n < 2:
if n == 0:
p = random.randint(1, 100)
a1 = primo(p)
if n ==1:
q = random.randint(1, 100)
b1 = primo(q)
n = a1*b1
en = (a1-1)*(b1-1)
print "N = ",n
print "en =",en
e = random.randint(1,(en -1))
print "valor de e:",e
gcd(en,e)
print modul
euclides(n,e)
##this code i found in i used this only for comprobate my result in paper
##only this no my :C
##link where i found this: http://www.slideshare.net/jpadillaa/criptografia-asimetrica-rsa
#sorry for this :C
#def egcd(a,b):
# u,u1=1,0
# v,v1 =0,1
# while b:
# q = a//b
# u,u1 = u1,u -q*u1
# v,v1 =v1,v-q*v1
# a,b = b,a-q*b
# return u,v,a
#def modInverse(e,n):
# return egcd(e,n)[0]%n
#d = modInverse(13,25)
#print "deeee=",d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment