예제 #1
0
def listen(user_list, message_hist):
  s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
  assert s
  s.bind(('', 6283))
  while 1:
    s.listen(1)
    assert s
    (conn , addr) = s.accept()
    mess = conn.recv(1024).decode() #decode convers from bin to string
                                    #Hangs untill message is recieved
    assert mess                                    
    ## FORK HERE TO DECODE WHILE STILL BEING ABLE TO ACCEPT A NEW MESSAGE
    #convert to list
    mess_list = [ord(mess[i]) for i in range(len(mess))]
    # decrypt
    dec_mess = saber.decrypt(mess_list, 20, user_list.key)
    # convert to string
    message = ''
    for i in range(len(dec_mess)):
      message = message + chr(dec_mess[i])
     
    rec_mess = protocol.read_message(message) #piece out message
    assert rec_mess
    if not rec_mess or rec_mess[2] == '' or rec_mess[2] == '\n': ##Empty message recieved
      None
    elif(user_list.search_users(rec_mess[0][0])):
      print('\n' + rec_mess[0][0] + ':\t' + rec_mess[2] + '\n' + input_message, end = '')
      message_hist.add_message(rec_mess[0][0], rec_mess[1][0], rec_mess[2])
    else:
      #Send error message
      print('\n<<Message recieved from unknon user and discarded>>\n' + input_message, end = '')
  return
예제 #2
0
def listen(user_list, message_hist):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    assert s
    s.bind(('', 6283))
    while 1:
        s.listen(1)
        assert s
        (conn, addr) = s.accept()
        mess = conn.recv(1024).decode()  #decode convers from bin to string
        #Hangs untill message is recieved
        assert mess
        ## FORK HERE TO DECODE WHILE STILL BEING ABLE TO ACCEPT A NEW MESSAGE
        #convert to list
        mess_list = [ord(mess[i]) for i in range(len(mess))]
        # decrypt
        dec_mess = saber.decrypt(mess_list, 20, user_list.key)
        # convert to string
        message = ''
        for i in range(len(dec_mess)):
            message = message + chr(dec_mess[i])

        rec_mess = protocol.read_message(message)  #piece out message
        assert rec_mess
        if not rec_mess or rec_mess[2] == '' or rec_mess[
                2] == '\n':  ##Empty message recieved
            None
        elif (user_list.search_users(rec_mess[0][0])):
            print('\n' + rec_mess[0][0] + ':\t' + rec_mess[2] + '\n' +
                  input_message,
                  end='')
            message_hist.add_message(rec_mess[0][0], rec_mess[1][0],
                                     rec_mess[2])
        else:
            #Send error message
            print('\n<<Message recieved from unknon user and discarded>>\n' +
                  input_message,
                  end='')
    return
예제 #3
0
# functions in the TauNet program.

# My Libs
import main, saber, messages, protocol, user_func
# Built in Libs
import time, threading

## saber.py
print("<<<< <<<< <<<< Testing Saber.py >>>> >>>> >>>>")
print("Testing encryption:")
test_string = "1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ `~!@#$%^&*()_+-=[]\{}|;,./<>? '" + '"'
print("Unencrypted Test String: " + test_string)
t_string = [ord(test_string[i]) for i in range(len(test_string))]
enc_test_string = saber.encrypt(t_string, 20, 'password')
print("Testing decryption:")
dec_t_string = saber.decrypt(enc_test_string, 20, 'password')
dec_test_string = ''
for i in range(len(dec_t_string)):
    dec_test_string = dec_test_string + chr(dec_t_string[i])
print("Decrypted Test STring: " + dec_test_string)
test_string = 'Al Dakota buys'
t_string = [ord(test_string[i]) for i in range(len(test_string))]
print("Standardized CipherSaber-2 Test String:\n" + test_string)
dec_t_string = saber.decrypt(t_string, 20, 'Al')
dec_test_string = ''
for i in range(len(dec_t_string)):
    dec_test_string = dec_test_string + chr(dec_t_string[i])
print("mead == " + dec_test_string)
wait = input("[Enter to Contine]")
wait = None
예제 #4
0
# functions in the TauNet program.

# My Libs
import main, saber, messages, protocol, user_func
# Built in Libs
import time, threading

## saber.py
print("<<<< <<<< <<<< Testing Saber.py >>>> >>>> >>>>")
print("Testing encryption:")
test_string = "1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ `~!@#$%^&*()_+-=[]\{}|;,./<>? '" + '"'
print("Unencrypted Test String: " + test_string)
t_string = [ord(test_string[i]) for i in range(len(test_string))]
enc_test_string = saber.encrypt(t_string, 20, 'password')
print("Testing decryption:")
dec_t_string = saber.decrypt(enc_test_string, 20, 'password')
dec_test_string = ''
for i in range(len(dec_t_string)):
  dec_test_string = dec_test_string + chr(dec_t_string[i])
print("Decrypted Test STring: " + dec_test_string)
test_string = 'Al Dakota buys'
t_string = [ord(test_string[i]) for i in range(len(test_string))]
print("Standardized CipherSaber-2 Test String:\n" + test_string)
dec_t_string = saber.decrypt(t_string, 20, 'Al')
dec_test_string = ''
for i in range(len(dec_t_string)):
  dec_test_string = dec_test_string + chr(dec_t_string[i])
print("mead == " + dec_test_string)
wait = input("[Enter to Contine]")
wait = None