Advertisement
ccbeginner

solve_n

Nov 27th, 2022
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 54.25 KB | None | 0 0
  1. "LLL Reduction... ",end='')
  2. LLL.reduction(M)
  3. print("Done!")
  4. b1 = M[-63]
  5. b2 = M[-62]
  6. print("b1 =",b1)
  7. print("b2 =",b2)
  8. n1 = 1
  9. n2 = 1
  10. p1 = 1
  11. p2 = 1
  12. for i in range(64):
  13.     if b1[i] < 0:
  14.         n1 *= pow(c[i], -b1[i])
  15.     else:
  16.         p1 *= pow(c[i], b1[i])
  17.    
  18.     if b2[i] < 0:
  19.         n2 *= pow(c[i], -b2[i])
  20.     else:
  21.         p2 *= pow(c[i], b2[i])
  22. sum1 = abs(p1-n1)
  23. sum2 = abs(p2-n2)
  24. print("Finish Counting sum1 sum2!")
  25.  
  26. import math
  27. print("Digit of sum1 =", math.log2(sum1)+1)
  28. print("Digit of sum2 =", math.log2(sum2)+1)
  29.  
  30. def GCD(a, b):
  31.     while b:
  32.         a, b = b, a%b
  33.     return a
  34. n = GCD(sum1, sum2)
  35. print("Finish GCD, n =",n)
  36. assert(n % p == 0)
  37.  
  38. assert(n % p == 0)
  39. for i in range(64):
  40.     for j in range(i+1, 64):
  41.         ci = pow(c[i], e[j], n)
  42.         cj = pow(c[j], e[i], n)
  43.         n = GCD(n, abs(ci-cj))
  44. print("Found n =",n)
  45. assert(n % p == 0)
  46.  
  47. from ecdsa.numbertheory import inverse_mod
  48.  
  49. q = n//p
  50.  
  51. for i in range(64):
  52.     if(GCD(e[i], (p-1)*(q-1)) > 1):
  53.         continue
  54.     d = inverse_mod(e[i], (p-1)*(q-1))
  55.     m = pow(c[i], d, n)
  56.     print(m)
  57.     print(int(m).to_bytes(256, byteorder='little'))
  58.     assert(pow(m, e[i], n) == c[i])
  59.     break
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement