Esempio n. 1
0
def load_chats():
    with open("chats.csv", "r") as chats_data:
        reader = csv.reader(chats_data)
        for row in reader:
            if row[2] == spy.get_spy_name() or row[3] == spy.get_spy_name():
                chat_message = ChatMessage()
                chat_message.set_message(row[0])
                chat_message.set_time(row[1])
                chat_message.set_sender(row[2])
                chat_message.set_receiver(row[3])
                chat_message.set_target_path(row[4])
                chat_message.set_output_path(row[5])
                spy.get_chats().append(chat_message)
Esempio n. 2
0
def send_message():
    print("\nSelect a friend to send a message to:")

    friend_choice = select_friend()

    # If the friend is not found, end the function
    if friend_choice == -1:
        print("Sorry! You entered an incorrect index.")
        return

    friend = spy.get_spy_friends()[friend_choice - 1]

    message, target_path, output_path = None, None, None

    # Input the message
    while True:
        message = input("Enter message below:\n")

        if len(message) > 0:
            break
        else:
            print("Please enter a message.")

    # Input the target image
    while True:
        target_path = input("Enter the directory of the target image:\n")

        if len(target_path) > 0:
            break
        else:
            print("Please enter a target directory.")

    # Input the output image
    while True:
        output_path = input("Enter the directory of the output image:\n")

        if len(output_path) > 0:
            break
        else:
            print("Please enter an output directory.")

    try:
        print("Encoding your message...")
        # Steganography.encode(target_path, output_path, message)

        # Encode the message and then save it at the output path
        secret = lsb.hide(target_path, message)
        secret.save(output_path)
        print("Done!")

        # Now add the message to the chat list as well
        chat_message = ChatMessage()
        chat_message.set_message(message)
        chat_message.set_time(datetime.now().strftime("%H:%M:%S"))
        chat_message.set_sender(spy.get_spy_name())
        chat_message.set_receiver(friend.get_spy_name())
        chat_message.set_target_path(target_path)
        chat_message.set_output_path(output_path)
        spy.get_chats().append(chat_message)

        # Write the message details into chats.csv
        with open("chats.csv", "a") as chats_data:
            writer = csv.writer(chats_data)
            writer.writerow([
                chat_message.get_message(),
                chat_message.get_time(),
                chat_message.get_sender(),
                chat_message.get_receiver(),
                chat_message.get_target_path(),
                chat_message.get_output_path()
            ])

    except IOError:
        pass