The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Fast Furious
By Guest on 20th January 2023 09:53:12 AM | Syntax: TEXT | Views: 3



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. import math
  2. #input variables
  3. p = int(input("Enter p: "))
  4. q = int(input("Enter q: "))
  5. message = int(input("Enter message: "))
  6. #calculate n
  7. n = p*q
  8. #calculate totient
  9. totient = (p-1)*(q-1)
  10. #calculate K
  11. for k in range(2,totient):
  12.     if math.gcd(k,totient)== 1:
  13.         break
  14.  
  15.  
  16. for i in range(1,10):
  17.     x = 1 + i*totient
  18.     if x % k == 0:
  19.         d = int(x/k)
  20.         break
  21.    
  22. local_cipher =pow(message,k)
  23. cipher_text = local_cipher % n
  24.  
  25. decrypt_t= pow(cipher_text,d)
  26. decrpyted_text = decrypt_t % n
  27.  
  28. print('n = '+str(n))
  29. print(' k = '+str(k))
  30. print(' totient = '+str(totient))
  31. print(' d = '+str(d))
  32. print('cipher text = '+str(cipher_text))
  33. print(' decrypted text = '+str(decrpyted_text))



  • Recent Pastes
  • Questions
    12 hours 46 mins 36 secs ago
  • Adrs
    12 hours 51 mins 46 secs ago
  • Docs
    12 hours 52 mins 30 secs ago
  • Servs
    12 hours 53 mins 13 secs ago
  • Srvs
    12 hours 58 mins 2 secs ago