Ejemplo n.º 1
0
    def encrypt(self, inp):
        print(self.__public.k)
        print(self.__public.m)

        return [
            successive_square(i, self.__public.k, self.__public.m) for i in inp
        ]
Ejemplo n.º 2
0
def probably_prime(n):
    if n == 1 or n == 2:
        return False
    if n == 3:
        return True

    for a in ten_rands(2, int(math.sqrt(n - 1))):
        if successive_square(a, n - 1, n) != 1:
            return False
    return True
Ejemplo n.º 3
0
def probably_prime(n):
    if n == 1 or n == 2:
        return False
    if n == 3:
        return True

    for a in ten_rands(2, int(math.sqrt(n - 1))):
        if successive_square(a, n - 1, n) != 1:
            return False
    return True
Ejemplo n.º 4
0
def solve(k, b, m, factors=None):
    #print("solve(k=%d,b=%d,m=%d" % (k, b, m))
    #if gcd(b, m) != 1:
    #    raise BaseException("B and m not relatively prime")
    phi = euler_phi(m, factors)

    if gcd(phi, k) != 1:
        raise BaseException("phi and k not relatively prime")

    for g, u, v in gxy_ascending(k, phi):
        if u >= 0:
            return successive_square(b, u, m)
Ejemplo n.º 5
0
 def calculate_shared(self, y_other):
     return successive_square(y_other, self.e, self.p)
Ejemplo n.º 6
0
 def calculate_yi(self):
     return successive_square(self.x, self.e, self.p)
Ejemplo n.º 7
0
def expotentiate(text, p, e):
    return [successive_square(c, e, p) for c in __codec.encode(KeyPair(PublicKey(m=p, k=e), None), text)]
Ejemplo n.º 8
0
def unsign(nums, e_from, n_from, e_to, n_to):
    dec = [successive_square(solve(e_to, i, n_to), e_from, n_from) for i in nums]
    return __codec.decode(None, dec)
Ejemplo n.º 9
0
def sign(text, e_from, n_from, e_to, n_to):
    pair_encode = KeyPair(PublicKey(m=min(n_from, n_to), k=-1), None)
    nums = __codec.encode(pair_encode, text)
    return [successive_square(solve(e_from, i, n_from), e_to, n_to) for i in nums]
Ejemplo n.º 10
0
def enrsa(text, e, n):
    return [successive_square(c, e, n) for c in __codec.encode(KeyPair(PublicKey(m=n, k=e), None), text)]
    pass
Ejemplo n.º 11
0
    def encrypt(self, inp):
        print(self.__public.k)
        print(self.__public.m)

        return [successive_square(i, self.__public.k, self.__public.m) for i in inp]
Ejemplo n.º 12
0
def unsign(nums, e_from, n_from, e_to, n_to):
    dec = [
        successive_square(solve(e_to, i, n_to), e_from, n_from) for i in nums
    ]
    return __codec.decode(None, dec)
Ejemplo n.º 13
0
def sign(text, e_from, n_from, e_to, n_to):
    pair_encode = KeyPair(PublicKey(m=min(n_from, n_to), k=-1), None)
    nums = __codec.encode(pair_encode, text)
    return [
        successive_square(solve(e_from, i, n_from), e_to, n_to) for i in nums
    ]
Ejemplo n.º 14
0
def enrsa(text, e, n):
    return [
        successive_square(c, e, n)
        for c in __codec.encode(KeyPair(PublicKey(m=n, k=e), None), text)
    ]
    pass