document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import socket
  2. from rsa_operations import *
  3. from sys import argv
  4. import time
  5.  
  6. filename = "passwords"
  7.  
  8. port = argv[1]
  9.  
  10. def search_password(host, pswd):
  11.   pswd = str(pswd)
  12.   f = open(filename, "r")
  13.   for line in f.readlines():
  14.     a, b = line.split(" ")
  15.     a, b = a.replace("\\n", ""), b.replace("\\n", "")
  16.     if a == host and b == pswd:
  17.       return True
  18.   return False
  19.  
  20.  
  21. rsa_math = RSAMath()
  22. p, q = rsa_math.random_primes(MAX)
  23. n = p*q
  24. phi_n = (p-1)*(q-1)
  25. e = rsa_math.random_e(phi_n)
  26. d = rsa_math.modinv(e, phi_n)
  27.  
  28. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  29. s.bind(("", int(port)))
  30. s.listen(3)
  31. sc, sddr = s.accept()
  32. rec = sc.recv(1024)
  33. if "connected" in rec:
  34.     host, tmp = rec.split(" ")
  35.     sc.send("e")
  36.     time.sleep(0.2)
  37.     sc.send(str(e))
  38.     time.sleep(0.2)
  39.     sc.send("n")
  40.     time.sleep(0.2)
  41.     sc.send(str(n))
  42. m = 0
  43. print "RSA Server"
  44. print "%s: Connected."%host
  45. while True:
  46.   rec = sc.recv(1024)
  47.   if rec == "c":
  48.     c = int(sc.recv(1024))
  49.     print "Recieved c: %s"%c
  50.     m = rsa_math.exp(c, d)%n
  51.     print "Decrypted m: %s"%m
  52.   if m!= 0 and search_password(host, m):
  53.     print "Host %s can be trusted"%host
  54.   else:
  55.     print "Host %s cannot be trusted. Terminating..."%host
  56.     time.sleep(1)
  57.     break
  58. sc.close()
  59. s.close()
');