Forging Digital Signatures

profileSpannRia
assignment.py

#!/usr/bin/python from blessings import Terminal import sys, getopt, socket, json BUFFER_SIZE = 2048 port=4635 host="192.168.1.40" print "Connecting to port " + str(port) # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: # Connect the socket to the port where the server is listening server_address = (host, port) #print >>sys.stderr, 'connecting to %s port %s' % server_address sock.connect(server_address) print 'Connected to %s port %s' % server_address except socket.error: print >>sys.stderr, "Could not connect to the server" exit(1) def printMenu(): print "Welcome to the assignment. Please make the following choice:" print "0. Get the ElGamal Parameters." print "1. Get a message, signature pair." print "2. Hash Checker." print "3. Print the message you need to forge a signature for." print "4. Submit a signature for a message." print "5. Exit." choice = raw_input(">> ") return choice while True: choice = printMenu() if choice == "5": print "Thank you. Good bye." exit() if choice == "4": r = raw_input("Enter the integer in base 10 for the R value in the signature: ") s = raw_input("Enter the integer in base 10 for the S value in the signature: ") sock.send("4:"+r+","+s) print sock.recv(2048) if choice == "3": sock.send("3\n") print sock.recv(2048) if choice == "2": m=raw_input("Please enter the message that you want to check the hash for: ") sock.send("2:"+m+'\n') print sock.recv(2048) if choice =="1": sock.send("1\n") msg = sock.recv(2048) (message, r, s) = msg.split('+') print "Message: " + message print "R: " + str(int(r,16)) print "S: " + str(int(s,16)) if choice == "0": sock.send("0\n") msg = sock.recv(2048) (p,g,y) = msg.split(",") print "P: " + str(int(p)) print "G: " + str(int(g)) print "Y: " + str(int(y))