def crt(C, N):
    Sum = 0
    NT = product(N)
    for c,n in zip(C,N):
        Sum += (c * product(minus(N,n)) * (eea(product(minus(N,n)),n) % n))
#     for c,n in zip(C,N):
#         if Sum % n != c:
#             print "Error CRT"
#             print Sum % n, c, n
#             exit()
    return Sum % NT
def crt(C, N):
    Sum = 0
    NT = product(N)
    for c, n in zip(C, N):
        Sum += (c * product(minus(N, n)) * (eea(product(minus(N, n)), n) % n))


#     for c,n in zip(C,N):
#         if Sum % n != c:
#             print "Error CRT"
#             print Sum % n, c, n
#             exit()
    return Sum % NT
from ModMath import eea, gcd
import math

plaintext = 120

p1 = 13
q1 = 23
n1 = p1 * q1
et1 = (p1-1) * (q1-1)
e1 = 7
#GCD must be 1 to work
if gcd(e1,et1) == 1:
    print "Good e"
else:
    print "Bad e"
d1 = eea(e1,et1) % et1
pub1 = e1,n1
priv1 = d1,n1
c1 = plaintext ** e1 % n1
print c1, n1, d1


p2 = 17
q2 = 11
n2 = p2 * q2
et2 = (p2-1) * (q2-1)
e2 = 7
#GCD must be 1 to work
if gcd(e2,et2) == 1:
    print "Good e"
else:
from ModMath import eea, gcd
import math

plaintext = 120

p1 = 13
q1 = 23
n1 = p1 * q1
et1 = (p1 - 1) * (q1 - 1)
e1 = 7
#GCD must be 1 to work
if gcd(e1, et1) == 1:
    print "Good e"
else:
    print "Bad e"
d1 = eea(e1, et1) % et1
pub1 = e1, n1
priv1 = d1, n1
c1 = plaintext**e1 % n1
print c1, n1, d1

p2 = 17
q2 = 11
n2 = p2 * q2
et2 = (p2 - 1) * (q2 - 1)
e2 = 7
#GCD must be 1 to work
if gcd(e2, et2) == 1:
    print "Good e"
else:
    print "Bad e"
Beispiel #5
0
import gensafeprime as prime
from ModMath import eea, gcd

# p = 7919
# q = 6271
# n = p * q
# et = (p-1) * (q-1)
# e = 97
# #GCD must be 1 to work
# print gcd(e,et)
# d = eea(e,et) % et
# pub = e,n
# priv = d,n
#
# plaintext = 1337808
# c = plaintext ** e % n
# m = c ** d % n
# print plaintext, c, plaintext == m
# print
# print c,n,d
# print c ** d % n
# print

p = 17
q = 11
n = p * q
et = (p - 1) * (q - 1)
e = 7
print gcd(e, et)
print eea(e, et) % et
import gensafeprime as prime
from ModMath import eea,gcd

# p = 7919 
# q = 6271
# n = p * q
# et = (p-1) * (q-1)
# e = 97
# #GCD must be 1 to work
# print gcd(e,et)
# d = eea(e,et) % et
# pub = e,n
# priv = d,n
# 
# plaintext = 1337808
# c = plaintext ** e % n
# m = c ** d % n
# print plaintext, c, plaintext == m
# print
# print c,n,d
# print c ** d % n
# print

p = 17
q = 11
n = p * q
et = (p-1) * (q-1)
e = 7
print gcd(e,et)
print eea(e,et) % et