My chinese remainder theorem python code works for integers with fewer than 23 digits

177 Views Asked by At

I am trying to implement a chinese remainder theorem based group key exchange scheme, it works well as long as the variable "gamma" in my code doesnt exceed 23 digits, once it does, the code doesnt work.

Ive posted my code for the working case, for the case that doesnt work i simply alter "low" and "high" to be 20,000 and 30,000 respectively, in order to generate larger primes. The problem is that when i generate larger primes, the value of gamma (towards the end of the code) exceeds 23 digits in size and then the code stops working

def CRT():
    low = 2000
    high = 3000
    p = generateprime(low, high)  # generates arbitrary prime number between low and high
    sk = []
    sk.append(p)
    for i in list(range(1, 5)):
        while p in sk:
            p = generateprime(low, high)
        sk.append(p)
    # sk= [19, 23, 29, 31, 37, 41, 43,47,53,59]
    print("sk=", sk)
    length = len(sk)
    prod = listmultiply(sk)  # returns the product of all the values in list sk
    print("product:", prod)
    xi = []
    for i in sk:
        xi.append(int(prod / i))

    print("xi=", xi)
    print("length=", length)
    yi = []
    check = []
    var = []
    for i in range(length):
        yi.append(pow(xi[i], -1, sk[i]))
        check.append((yi[i] * xi[i]) % sk[i])
        var.append(yi[i] * xi[i])
    print("yi:", yi)
    print("var:", var)
    print("check", check)
    mew = listadd(var)  # returns the sum of all the values in list var
    # mew=mew-var[4]  #test the group leave operation
    print("mew:", mew)
    rand = 80
    gamma = rand * mew
    print("gamma=", gamma)
    print("size=", len(str(gamma)))
    groupkey = []
    for i in sk:
        groupkey.append(gamma % i)
    print("group key:", groupkey)

Working Output: All members get the same group key

   sk= [2179, 2609, 2357, 2137, 2351]
   product: 67320610099918649
   xi= [30895185910931, 25803223495561, 28561989859957, 31502391249377, 28634883070999]
   length= 5
   yi: [1873, 1277, 468, 186, 859]
   var: [57866683211173763, 32950716403831397, 13367011254459876, 5859444772384122, 24597364557988141]
   check [1, 1, 1, 1, 1]
   mew: 134641220199837299
   gamma= 10771297615986983920
   size= 20  **#size of gamma is 20 digits and the code works**
   group key: [80, 80, 80, 80, 80]

Output that doesn't work: Members end up with different group keys

   sk= [26647, 28123, 29483, 29399, 21911]
   product: 14232342888783334179647
   """xi= [534106762066398976, 506074845812443008, 482730484984002112, 484109761855278528,                                                                      649552411518567552]"""
   length= 5
   yi: [16104, 91, 6383, 9455, 7982]
   var: [8601255296317289109504, 46052810968932313728, 3081268685652885480896,   4577257798341658482240, 5184727348741206200064]
   check [1, 1, 1, 1, 1]
   mew: 21490561940021971586432
   gamma= 1719244955201757726914560
   size= 25   **#size of gamma is 25 digits and the code doesnt work**
   group key: [25129, 4713, 12293, 7538, 5447]`
0

There are 0 best solutions below