def compute_S(self): A = int(self.get_A()) v = self.compute_v() u = self.compute_u() b = self.sk v_to_u = modexp(v, u, self.prime) base = (A * v_to_u) % self.prime exponent = b S = modexp(base, exponent, self.prime) return S
def test1(a, r_d, integer): ## Tests for given element a mod n whether a**d = 1. ## Note that we assume integer - 1 = (2 ** r) * d d = r_d[1] return modexp(a, d, integer) == 1
def compute_S(self): B = int(self.get_B()) a = self.sk u = self.compute_u() v = self.compute_v() x = self.compute_x() base = (B - k * v) % self.prime exponent = (a + u * x) return modexp(base, exponent, self.prime)
def test2(a, r_d, integer): ## Tests for given element a mod n whether a ** (2s * d) = pm 1 ## for some s between 0 and r - 1 r, d = r_d[0], r_d[1] output = modexp(a, d, integer) for s in range(0, r): if output == 1 or output == integer - 1: return True output = modsquare(output, integer) return False
def decrypt(self, number): decrypted = modexp(number, self.private_key, self.modulus) decrypted = self.number_to_string(decrypted) return decrypted
def encrypt(self, string): string = self.string_to_number(string) encrypted = modexp(string, self.public_key, self.modulus) return encrypted
def compute_v(self): x = self.compute_x() v = modexp(self.generator, x, self.prime) return v
def public_key(self): pk = modexp(self.generator, self.sk, self.prime) return pk
def exponent_test(a, b): x = modexp(2, a, nist_prime) y = modexp(x, b, nist_prime) z = modexp(2, a * b, nist_prime) return y == z