document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import socket
  2. from rsa_operations import *
  3. import math
  4. import time
  5. from sys import argv
  6.  
  7. def search_private_key(hostname):
  8.   f = open("%s.dat"%hostname, "r")
  9.   for line in f.readlines():
  10.     n, d = line.split(" ")
  11.   return int(d), int(n)
  12.  
  13.  
  14. hostname = argv[1]
  15. port = int(argv[2])
  16.  
  17. rsa_math = RSAMath()
  18.  
  19. d, n = search_private_key(hostname)
  20.  
  21. s = socket.socket()
  22.  
  23. #print "d = %s"%d
  24. #print "n = %s"%n
  25.  
  26. s.connect(("127.0.0.1", port))
  27. s.send("%s connected"%hostname)
  28. time.sleep(.2)
  29.  
  30. while True:
  31.   rec = s.recv(1024)
  32.   if rec == "r":
  33.     r = s.recv(1024)
  34.     #print "Recieved r: %s"%r
  35.     y = rsa_math.function(int(r))
  36.     #print "Normal y: %s"%y
  37.     m = rsa_math.exp(y, d)%n
  38.     #print "Encrypted y: %s"%m
  39.     s.send("c")
  40.     time.sleep(.2)
  41.     s.send(str(m))
  42.   if rec == "ok":
  43.     print "Correct Authentication"
  44.     print "Welcome!. You are now in the chat"
  45.     while(True):
  46.       msg = raw_input()
  47.       print "%s says: %s"%(hostname, msg)
  48.       s.send("%s says: %s"%(hostname, msg))
  49.    
  50. s.close()
');