コード例 #1
0
def netThrow(conn, secret, message):
    """Sends message through the open socket conn with the encryption key
    secret. Sends the length of the incoming message, then sends the actual
    message.
    """
    try:
        conn.send(monoalphabetic.encrypt(key,
                                         message))  #send encrypted message
    except socket.error:
        if len(conn_array) != 0:
            writeToScreen("Connection issue. Sending message failed.",
                          "System")
            processFlag("-001")
コード例 #2
0
def whiteNoise(conn, secret):
    #while loop for white noise

    while (1):
        message = "pzt "  #the space allows filtering via .split(" ") later

        i = random.randint(5, 10)  #choose a random number of characters to add
        for x in range(0, i):
            message += random.choice(
                string.letters)  #append a random upper/lower letter

        #time.sleep(0.1)
        time.sleep(random.random(
        ))  #sleep() pauses the thread of activity a certain length of time
        #random() gives random float [0,1)
        try:
            conn.send(monoalphabetic.encrypt(
                key, message))  #send encrypted garbage message
        except socket.error:
            if len(conn_array) != 0:
                writeToScreen("Connection issue. Sending message failed.",
                              "System")
コード例 #3
0
 def test_string_without_space(self):
     plaintext = 'defendtheeastwallofthecastle'
     key = 'qmrhsnxbwpgjauoecklfzyvtdi'
     ciphertext = 'hsnsuhfbssqlfvqjjonfbsrqlfjs'
     self.assertEqual(ciphertext, monoalphabetic.encrypt(plaintext, key)) and self.assertEqual(plaintext, monoalphabetic.decrypt(ciphertext, key))