Example #1
0
name="server" #Change to client for test on deterlab
HOST = name
PORT = 16007
ADDR = (HOST,PORT)
BUFSIZE = 4096

cli = socket( AF_INET,SOCK_STREAM)
cli.connect((ADDR))

#Receive type of cipher to use and any additional info
data = cli.recv(BUFSIZE)
dataSplit = str(data).split()

if(dataSplit[0] == "a"):
	crypt = Alphabetic(1)

elif(dataSplit[0] == "b"):
	crypt = Alphabetic(4)
	
elif(dataSplit[0] == "c"):
	crypt = Homophonic()
	
elif(dataSplit[0] == "d"):
	crypt = Polygram()

#Begin receiving file, decrypting, and logging
f = file("messages.txt","w+")

while(True):
	data = cli.recv(BUFSIZE) #Receive the message from server
Example #2
0
serv.listen(5)    #5 is the maximum number of queued connections we'll allow
print ("listening...")
request=0
conn,addr = serv.accept() #accept the connection
print ("...connected!")


#Setup which cipher type and additional info needed
while(True):
	#Choose cipher type
	ciphertype = raw_input("Select cipher letter choice: a) monoalphabetic, b) polyalphabetic, c) homophonic, d) polygram : ")
	print(ciphertype)
	if(ciphertype == "a"):
		choice = "a"
		conn.send(choice)
		crypt = Alphabetic(1)
		break

	elif(ciphertype == "b"):
		maplen = input("How many maps to use: ")
		choice = "b " + str(maplen)
		conn.send(choice)
		crypt = Alphabetic(maplen)
		break

	elif(ciphertype == "c"):
		choice = "c"
		conn.send(choice)
		crypt = Homophonic()
		break