Beispiel #1
0
def encryptor(entire_msg, key):
    K1, K2 = toy_des.key_getter(key)
    # see, I'm going to operate under the assumption that entire_msg is already in bits
    # so I don't need to do text_to_bits
    # turning bits to bits because it'll convert easier lollllllll
    bits_of_bits = toy_des.text_to_bits(entire_msg)
    block_list = []
    block = ""
    for i in range(0, len(bits_of_bits), 8):
        for j in range(i, i + 8):
            if j == len(bits_of_bits):
                break
            block += bits_of_bits[j]
        block_list.append(block)
        block = ""

    encrypt_list = []
    encrypt_string = ""
    for i in range(len(block_list)):
        encrypt_list.append(toy_des.encryptor(block_list[i], K1, K2))

    for i in range(len(encrypt_list)):
        encrypt_string += toy_des.text_from_bits(encrypt_list[i])

    return encrypt_string
Beispiel #2
0
def decryptor(entire_msg, key):
    K1, K2 = toy_des.key_getter(key)
    decrypt_list = []
    encrypt_bits = toy_des.text_to_bits(entire_msg)

    block = ""
    for i in range(0, len(encrypt_bits), 8):
        for j in range(i, i + 8):
            block += encrypt_bits[j]
        decrypt_list.append(block)
        block = ""

    decrypt_bits = []
    for i in range(len(decrypt_list)):
        decrypt_bits.append(toy_des.decryptor(decrypt_list[i], K1, K2))
    block = ""
    for i in range(len(decrypt_bits)):
        block += toy_des.text_from_bits(decrypt_bits[i])

    return block
Beispiel #3
0
    block = ""
    # print(len(secret_bin))
    for i in range(0, len(secret_bin), 8):
        for j in range(i, i + 8):
            if j == len(secret_bin):
                break
            block += secret_bin[j]
        block_list.append(block)
        block = ""

    Key1, Key2 = toy_des.key_getter(key)

    encrypt_list = []
    encrypt_string = ""
    for i in range(len(block_list)):
        encrypt_list.append(toy_des.encryptor(block_list[i], Key1, Key2))

    for i in range(len(encrypt_list)):
        encrypt_string += toy_des.text_from_bits(encrypt_list[i])

    # want to send the encrypted string
    # listen for incoming connections
    sock.listen(1)
    while True:
        try:  # this will just keep sending the encrypted message
            connection, cli_addr = sock.accept()
            print("connection from:", cli_addr)
            print("sending the encrypt_string of the message:", encrypt_string)
            connection.sendall(encrypt_string.encode())
        finally:
            connection.close()
Beispiel #4
0
    while True:
        encrypted = sock.recv(1024).decode()

        print("Received the message:", encrypted)

        # this is pretty much the same code from toy_des.
        # it's just the decryption process
        decrypt_list = []
        encrypt_bits = toy_des.text_to_bits(encrypted)

        block = ""
        for i in range(0, len(encrypt_bits), 8):
            for j in range(i, i + 8):
                # print(j)
                block += encrypt_bits[j]
            decrypt_list.append(block)
            block = ""

        decrypt_bits = []
        for i in range(len(decrypt_list)):
            decrypt_bits.append(toy_des.decryptor(decrypt_list[i], K1, K2))

        block = ""
        for i in range(len(decrypt_bits)):
            block += toy_des.text_from_bits(decrypt_bits[i])

        print("The decrpyted string is:", block)
        f.write(block)
        f.close()
        break