Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. from functions import *
  2.  
  3. #choose 2 primes (both 2^n bites long)
  4. p = input("Choose prime 1: ")
  5. q = input("Choose prime 2: ")
  6. #print ("size of p: " + str(len("{0:b}".format(p))) + " size of q: " + str(len("{0:b}".format(q)))) #from stackoverflow: formats binary number
  7.  
  8. n = p * q #will be 2^(n+1) bites long
  9.  
  10. phin = (p-1)*(q-1)
  11. m = input("Message smaller than " + str(n) + ": ")
  12.  
  13. e = 3 #cant be two because phin will always be even
  14. while (phin/float(e)).is_integer() == 1: #needs improvement
  15. e += 2
  16.  
  17. k = 1
  18. d = ((k*phin)+1)/e #
  19. while (((k*phin)+1)/float(e)).is_integer() != 1: #
  20. d = ((k*phin)+1)/e #
  21. k += 1
  22.  
  23. print ("e: " + str(e))
  24. print ("k: " + str(k))
  25.  
  26. c = mod((m ** e), n)
  27. print c
  28.  
  29. newm = mod(((mod(c, n)) ** d), n)
  30. print m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement