Guest User

Untitled

a guest
Apr 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. def egcd(a, b):
  2. x,y, u,v = 0,1, 1,0
  3. while a != 0:
  4. q, r = b//a, b%a
  5. m, n = x-u*q, y-v*q
  6. b,a, x,y, u,v = a,r, u,v, m,n
  7. gcd = b
  8. return gcd, x, y
  9.  
  10. def main():
  11. p = 31633324922152208667782365945327593684774069143774669661619572762724400715661831
  12. q = 36515984267977612350498121647561131263792046107668364547689126140974588406556229
  13. e = 65537
  14. ct = 3850399659456144909054023356222104703474998103430205103288738594544245075326232
  15. 52932642491630030372490846191037269295383730831605896115604912885466639330684242
  16.  
  17. # compute n
  18. n = p * q
  19.  
  20. # Compute phi(n)
  21. phi = (p - 1) * (q - 1)
  22.  
  23. # Compute modular inverse of e
  24. gcd, a, b = egcd(e, phi)
  25. d = a
  26.  
  27. print( "d: " + str(d) );
  28.  
  29. # Decrypt ciphertext
  30. pt = pow(ct, d, n)
  31. print( "Message: " + str(pt) )
  32.  
  33. if __name__ == "__main__":
  34. main()
Add Comment
Please, Sign In to add comment