import socket
from rsa_operations import *
from sys import argv
from random import randint
import time
rsa_math = RSAMath()
host, port = argv[1], argv[2]
s = socket.socket()
s.connect(("127.0.0.1", int(port)))
print "Enter your password:"
m = int(raw_input())
s.send("%s connected."%host)
e, n = 0, 0
while True:
rec = s.recv(1024)
if rec == "e":
e = int(s.recv(1024))
print "Received e: %s"%e
if rec == "n":
n = int(s.recv(1024))
print "Received n: %s"%n
if e != 0 and n != 0:
print "Original m: %s"%m
c = rsa_math.exp(m, e) % n
print "Ciphertext: %s"%c
s.send("c")
s.send(str(c))
s.close()