예제 #1
0
    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
예제 #2
0
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
예제 #3
0
    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)
예제 #4
0
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
예제 #5
0
    def decrypt(self, number):

        decrypted = modexp(number, self.private_key, self.modulus)
        decrypted = self.number_to_string(decrypted)
        return decrypted
예제 #6
0
    def encrypt(self, string):

        string = self.string_to_number(string)
        encrypted = modexp(string, self.public_key, self.modulus)
        return encrypted
예제 #7
0
    def compute_v(self):

        x = self.compute_x()
        v = modexp(self.generator, x, self.prime)
        return v
예제 #8
0
    def public_key(self):

        pk = modexp(self.generator, self.sk, self.prime)
        return pk
예제 #9
0
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