Beispiel #1
0
def test_stegano():
    path = "/tmp/image/a.jpg"
    output_path = "/tmp/image/b.jpg"
    text = 'The quick brown fox jumps over the lazy dog.'

    Steganography.encode(path, output_path, text)
    secrete_text = Steganography.decode(output_path)
    assert secrete_text == text
def send_message():
    frnd = select_friend()
    avg = 0
    pattern = '^[a-zA-Z0-9\s]+\.jpg$'
    while True:
        original_image = raw_input('Name of image:')
        if re.match(pattern, original_image) != None:
            break
        else:
            print 'File should must have .jpg extension'
    while True:
        output_image = raw_input('Name of output image:')
        if re.match(pattern, output_image):
            break
        else:
            print 'File should must have .jpg extension'
    while True:
        text = raw_input('Enter your message:')
        pattern = '^[a-zA-Z0-9@$%&\s]+$'
        if re.match(pattern, text) != None:
            break
        else:
            print 'Enter alphabets only'
    msg1 = 'SAVE ME'
    msg2 = 'HELP'
    msg3 = 'SOS'
    msg4 = 'EMERGENCY'
    # help1 = text.find(msg1) + text.find(msg1.lower())
    # help2 = text.find(msg2) + text.find(msg2.lower())
    # help3 = text.find(msg3) + text.find(msg3.lower())
    # help4 = text.find(msg4) + text.find(msg4.lower())
    # Checking for an emergency message
    if msg1 or msg1.lower() or msg2.lower() or msg3.lower() or msg4.lower() in text:
        # Encryption of image:
        try:
            Steganography.encode(original_image, output_image, text)
            avg = len(text)
            new_chat = ChatMessage(text, True, avg, frnd)
            friends[frnd].chats.append(new_chat)
            print '\nIt seems you are in danger.'
            print 'Don\'t you worry my friend.'
            print 'I\'m on my way.'
            print "Your secret message image is ready!"
        except IOError:
            print 'No such file present in your directory.'
            print 'Try:demo.jpg\n'
            sleep(0.5)
    else:
        # Encryption of image:
        try:
            Steganography.encode(original_image, output_image, text)
            new_chat = ChatMessage(text, True, avg, frnd)
            friends[frnd].chats.append(new_chat)
            print "Your emergency secret message image is ready!"
        except IOError:
            print 'No such file present in your directory.'
            print 'Try:demo.jpg\n'
            sleep(0.5)
Beispiel #3
0
def send_a_message():
    select_friend = select_a_friend()
    original_image = raw_input("what is the name ofthe image")
    output_path = original_image
    text = raw_input("what message do u want to send ? ")
    if len(text) <= 0:
        print("u cannot send empty message!!!!")
    elif len(text) > 100:
        print("you exceed the message limit .. please try again later!!!!")
        del friends[select_friend]
    else:
        Steganography.encode(original_image, output_path, text)
        chats = chatmessage(text, True)
        friends[select_friend].chat.append(chats)
        print("your secret message is ready.")
Beispiel #4
0
def send_message():
  try:
    friend_choice = select_a_friend()

    original_image = raw_input("What is the name of the image?")
    output_path = "output.jpg"
    text = raw_input("What do you want to say? ")
    Steganography.encode(original_image, output_path, text)

    new_chat = ChatMessage(text,True)

    friends[friend_choice].chats.append(new_chat)

    print "Your secret message image is ready!"
  except TypeError:
      print "Your image does not contain any message."
Beispiel #5
0
def send_message():
    friend_choice = select_friend()
    ecrypted_words = []
    original_image = raw_input("What is the name of the image?")
    output_image = raw_input("Please name the outfile file : *.jpg")
    text = raw_input("What do you want to say?")
    encrypted_words = show_encryption_menu(text)
    for words in range(len(encrypted_words)):
        Steganography.encode(original_image, output_image, words)
    new_chat = {
        "message": sender_text,
        "time": datetime.now(),
        "sent_by_me": True
    }
    friends[friend_choice]['chats'].append(new_chat)
    print "Your secret message is ready!"
Beispiel #6
0
def read_message():

    sender = select_a_friend()

    output_path = raw_input(colored("What is the name of the file?", "yellow"))

    secret_text = Steganography.decode(output_path)

    def verify_message(self, message, friend_id):
        # conditioning and removing the friend if length of the message is above 100 letters
        if len(message) > 100:
            print "Your Friend %s %s is removed due to spamming" % (
             self.spy.friends[friend_id].salutation, self.spy.friends[friend_id].name)
            self.spy.friends.pop(friend_id)
            return False
# special messages with their definitions
        elif message == "SOS":
            print "Save Our Ship"
        elif message == "SAVE ME":
            print "Hey save me I'm in Danger"
        elif message == "HELP ME":
            print "I need Help as soon as possible"
        return True

    new_chat = ChatMessage(secret_text, False)

    friends[sender].chats.append(new_chat)

    print "Your secret message has been saved!"
Beispiel #7
0
def read_message():
    global total_words
    global total_images

    total_images += 1
    sender = select_a_friend()

    output_path = raw_input("What is the name of the file?")

    secret_text = Steganography.decode(output_path)

    new_chat = ChatMessage(secret_text, False)

    if secret_text == "SOS" or secret_text == "SAVE ME":
        print colored('\nReinforcement will soon be their\n', 'red')

    if len(secret_text) > 0:
        wordList = re.sub("[^\w]", " ", secret_text).split()
        if len(wordList) > 100:
            del friends[sender]
        else:
            total_words += len(wordList)
            friends[sender].chats.append(new_chat)
            print "Your secret message has been saved!"
    else:
        print "Image is not having any secret massage"
Beispiel #8
0
def send_a_message():
    #choose from the list of spy friends added by the user
    friend_choice = select_a_friend()
    print friend_choice
    #name of the image user want to encode the secret message with
    original_image = raw_input("What is the name of the image?")
    original_image = "secret\%s" % (original_image)
    output_path = raw_input("Save image as")
    #secret message want to hide
    output_path = "secret\%s" % (output_path)
    text = raw_input("What do you want to say? ")
    Steganography.encode(original_image, output_path, text)
    new_chat = ChatMessage(text, True)
    #Append the chat message to 'chats' key for the friends list
    FRIENDS[friend_choice].chats.append(new_chat)
    print "Your secret message image is ready!"
Beispiel #9
0
def read_message():  #reading a message
    select_friend = select_frnd()  #index value
    output_path = raw_input('Which image you want to decode ? '
                            )  # asking the user for an input of image
    secret_text = Steganography.decode(output_path)  #decoding message
    decode = int(
        secret_text[:1]
    )  #checking if the right person is decoding the message or not
    if decode == select_friend:
        secret_text = secret_text.replace(str(decode), '')
        predefined = ['SOS', 'SAVE ME', 'EMERGENCY']

        if secret_text.upper() in predefined:
            print 'WE NEED YOU:' + Fore.RED + secret_text  # Displaying for the user
            print(Style.RESET_ALL)
        else:

            print 'Secret text is:' + secret_text  # Displaying for the user

        new_chat = ChatMessage(secret_text, time.strftime("%d %m %H"),
                               spy.name, friends[select_friend].name)
        friends[select_friend].chats.append(
            new_chat)  # appending the friend chat detail
        print 'Your secret message has been saved...'  #Displaying for the user
    else:

        print "You are not correct person for decoding this message"  #displaying it for the user
Beispiel #10
0
def send_message():
    # now we have to encypt the text in image which is also called steanography

    friend_choice = select_a_friend()

    original_image = raw_input("What is the name of the image?")
    output_path = "decod.jpg"
    text = raw_input("What do you want to say? ")
    Steganography.encode(original_image, output_path,
                         text)  #here we are encrypting the msg the text

    new_chat = ChatMessage(text, True)

    friends[friend_choice].chats.append(new_chat)

    print "Your secret message image is ready!"
Beispiel #11
0
def read_message():
    selected_friend = select_frnd()  # calling select_friend function
    output_path = raw_input(
        "Which image you want to decode? ")  # the name of image to be decoded
    secret_text = Steganography.decode(
        output_path)  # calling decode()function to decode
    print "The decoded message is " + secret_text  # printing the secret text
Beispiel #12
0
def read_message():

    sender = select_friend()

    output_path = raw_input(colored("Name of the file?", 'red'))

    try:
        secret_text = Steganography.decode(output_path)
    except:
        print("not a valid message")
        return

    new_chat = ChatMssg(secret_text, False)

    friends[sender].chats.append(new_chat)

    print "The secret message is : \n" + secret_text

    if secret_text.upper() in SPECIAL_MESSAGES:
        print "We are on our way to help you"

    if (len(secret_text.split(" "))) > 100:
        print "This spy" + friends[
            sender].name + "was talking too much,therefore will be deleted from the list "
        del friends[sender]
Beispiel #13
0
def read_msg():   # reading the decoded msg using Steganography
    sender = select_a_friend()
    output_path = raw_input('What is the file name?')   # Writing the file name generated by Steganography
    secret_msg = Steganography.decode(output_path)      # Decoding the secret msg

    split_msg = secret_msg.split(" ")       # splitting the secret msg

    a = dic_special_words.keys()        # obtaining keys from the dictionary of special words

    place = 0
    for x in a:
        if x in split_msg:
            print 'Special words in msg %s: %s' %(x, dic_special_words.get(x))       # printing the special word with its value
            place = place+1
        else:
            continue

    if len(split_msg) > 100:   # removing the friend from list if they speak too much
        print '%s Has been removed from spy list !!' % (friends[sender].spy_name)
        friends.remove(friends[sender])
    if len(secret_msg) == 0:    # if image does not contain any msg
        print 'There is no message in the image ..'
    new_mesg = chatMessage(secret_msg, False)
    friends[sender].chats.append(new_mesg)      # appending msg to chats list

    print 'Your message is saved and secured.'
Beispiel #14
0
def send_a_secret_msg(spy_name):  # function for encoding msg
    friend = select_friend(
    )  # calling function to select a friend from friend list
    image_path = raw_input("enter image path : ")
    image_name = raw_input("enter image name with extension : ")
    secret_msg = raw_input("enter secret message you want to send")
    output_image = image_path + "\secret_image.jpg"
    Steganography.encode(image_path + "\\" + image_name, output_image,
                         secret_msg)  # encoding msg
    date_time = date()
    spy_chat[spy_name] = {
        friend: {
            'secret_msg': output_image,
            'time': date_time
        }
    }
Beispiel #15
0
def read_message():
 #calling select_a_friend method to get which friend is to be communicated with.
    sender = select_a_friend()
 #Ask the user for the name of the image they want to decode the message from.
    output_path = raw_input("What is the name of the file?")

    secret_text = Steganography.decode(output_path)
 #if image does not containing any message
    if not secret_text:
        print "Your image does not contain any message."


    new_chat = ChatMessage(secret_text,False)
    # Append the chat dictionary to chats key for the particular friend.
    friends[sender].chats.append(new_chat)

    print "Your secret message is:"
    print secret_text
 # Printing appropriate message for special words


    if secret_text == 'Saveme' or secret_text == "Help" or secret_text == "trouble" or secret_text == "Emergency":
     print "What can i do for u?"

     words = secret_text.split()  # Remove a spy for speaking too much
    if len(words) > 100:
        print "You are speaking too much."
        friends.remove(friends[sender])
    # printing message when average word reached
    if len(words) > 55:
         print "Average number of words reach"
def read_message(
):  # this function is defined to read a message sent by a friend

    dict_special_words = {
        'asap': 'as soon as possible',
        'lol': 'laugh out loud',
        'gtg': 'got to go'
    }

    sender = select_a_friend()

    output_path = raw_input("What is the name of the file?")

    secret_text = Steganography.decode(output_path)

    new_chat = ChatMessage(secret_text, False)

    if len(secret_text.split()
           ) > 50:  # Checking if the friend spoke more than 50 word
        friends.remove(friends[sender]
                       )  # Deleting the friend if he spoke more than 50 words
    elif len(secret_text
             ) == 0:  # Checking if the image contains any text or not
        print('there is no secret text in your image')
    else:
        for word in dict_special_words.keys():  # Checking special words
            found = secret_text.find(
                word
            )  # Checking if the the Secret_text contains special words or not
            if found != -1:
                print(word + '=' + dict_special_words[word])

        friends[sender].chats.append(new_chat)
        print secret_text
        print "Your secret message has been saved!"
Beispiel #17
0
def read_message():
    chosen_friend = select_friend()
    # asking the user for the image to be decoded
    output_path = raw_input(
        "Name of the image you want to decoded the message from(with extension)"
    )
    secret_message = Steganography.decode(output_path)
    try:
        # Using decode() function with file name of encrypted message as parameter
        secret_message = Steganography.decode(output_path)
        print(colored("Your secret message is:", "cyan"))
        print(colored(secret_message, "blue"))

        # Converting secret_text to uppercase and splitting
        new_text = (secret_message.upper()).split()

        # Checking emergency templates for help
        if 'SOS' in new_text or 'SAVE ME' in new_text or 'HELP ME' in new_text or 'ALERT' in new_text or 'RESCUE' in new_text or 'ACCIDENT' in new_text:

            # Emergency alert
            print colored(
                "!!!EMERGENCY MESSAGE DETECTED!!!",
                'grey',
            ),
            print colored("The friend who sent this message needs your help!",
                          "green")

            # Creating new chat
            new_chat = ChatMessage(spy.name, friends[chosen_friend].name,
                                   secret_message, False)
            # Appending to chats
            friends[chosen_friend].chats.append(new_chat)

        # If there are no emergency messages
        else:
            new_chat = ChatMessage(spy.name, friends[chosen_friend].name,
                                   secret_message, False)
            # Appending
            friends[chosen_friend].chats.append(new_chat)

            print colored("Your secret message has been saved.\n", 'cyan')

    # No message found exception
    except TypeError:
        print colored(
            "Nothing to decode from the image...\n Sorry! There is no secret message",
            'red')
Beispiel #18
0
def send_message():

    # choose a friend from the list to communicate
    friend_choice = select_friend()

    # select an image in which you want to hide a secret message.
    original_image = raw_input("Provide the name of the image to hide the message : ")
    pattern_i = '^[a-zA-Z]+\.jpg$'

    # name the output file
    output_image = raw_input("Provide the name of the output image  : ")
    pattern_o = '^[a-zA-Z]+\.jpg$'

    # write the secret message
    text = raw_input("Enter your message here : ")
    # Encrypt the message using Steganography library
    Steganography.encode(original_image, output_image, text)

    # the message will be stored in chat message class
    new_chat = ChatMessage(text, True)

    # along the name of friend with whom we add message
    friends[friend_choice].chats.append(new_chat)

    # Successful message after encoding
    print (colored("Your message encrypted successfully.", 'red'))

    # save the messages
    new_chat = {
        'message': text,
        'time': datetime.now(),
        'sent_by_me': True
    }

    # name of the friend along which we add message.
    friends[friend_choice].chats.append(new_chat)
    print (colored("your secret message is ready.",'yellow'))

    # users input validations
    if (re.match(pattern_i, original_image) != None and re.match(pattern_o, output_image) != None):
        print (colored('All perfect','red'))
    else:
        print (colored('Sorry! Invalid entry. We can\'t validate your input and output\n ', 'blue'))
        print (colored('The convention to follow is: \n ', 'blue'))
        print (colored('1. Input should ends with (.jpg) format.\n ', 'blue'))
        print (colored('2. Output should also ends with (.jpg) format.\n ', 'blue'))
        print (colored('Keep in mind and Try Again\n\n ', 'blue'))
Beispiel #19
0
def send_message():

    friend_choice = select_a_friend()

    original_image = raw_input("\nWhat is the name of the image?")
    output_path = "landscape.jpg"
    text = raw_input("\nWhat do you want to say? ")
    Steganography.encode(original_image, output_path, text)

    new_chat = ChatMessage(text, True)

    friend_list[friend_choice].chats.append(new_chat)

    # if len(new_chat)>0:
    #
    #
    print "\nYour secret message image is ready!"
Beispiel #20
0
def send_message():
    #selecting friend
    friend_choice = select_a_friend()
    #input path of image used for storing message
    original_image = raw_input("What is the name of the image?")
    #Path of image in which message will be hidden
    output_path = "C:\Users\New\PycharmProjects\spy_chat\Secret\output1.png"

    text = raw_input("What do you want to say? ")
    #encoding the message
    Steganography.encode(original_image, output_path, text)
    #if message contain text store it in variable new_chat and append
    new_chat = ChatMessage(text, True)

    friends[friend_choice].chats.append(new_chat)

    print "Your secret message image is ready!"
Beispiel #21
0
def read_a_message():
    selected_frnd = select_a_friend()
    output_path = raw_input("Which image you want to decode? ")  # asking about which image user need to decode
    secret_text = Steganography.decode(output_path)  # decoding the text from image
    print "Secret text is " + secret_text
    new_chat = ChatMessage(secret_text,False)
    friends[selected_frnd].chats.append(new_chat)  # appending
    print "Your secret message has been saved. "
Beispiel #22
0
    def send_message():
        #friend_choice is getting the friend to which we want to send message
        friend_choice = select_a_friend()
        original_image = raw_input("What is the name of the image?")
        output_path = "output.jpg"
        text = raw_input(colored('Enter your message?','red'))
        if text:
            if len(text)<100:
                Steganography.encode(original_image, output_path, text)
            else:
                print 'the length of message shoud not exceed 100'
        else:
            print 'empty string not allowed'
        new_chat = ChatMessage(text,True)

        friends[friend_choice].chats.append(new_chat)
        print 'your secret message is ready!'
Beispiel #23
0
def readmsg(spy_ab):
    get = raw_input("Enter the Name or Path of the image:\n-->")
    if len(get) > 0:
        read = Steganography.decode(get)
        print read
    else:
        print "Donot Understand"
    return
Beispiel #24
0
def sendMessage():
    friend_selected = select_friend()
    if friend_selected >= 0:
        original_image = raw_input("What is the name of the image?")
        output_path = 'output.jpeg'
        text = raw_input("What do you want to say?")
        Steganography.encode(original_image, output_path, text)

        new_chat = Chat(text, spy.name)

        friends[friend_selected].chats.append(new_chat)
        with open('chats.csv.txt', 'a') as chat_box:
            sender = csv.writer(chat_box)
            sender.writerow([friends[friend_selected].name, new_chat.message, new_chat.sent_by, new_chat.time])
        print "Your secret message image is ready!"
    else:
        print 'You seem to have no friends'
Beispiel #25
0
def send_message():
    # Selecting a friend to send message
    selected_frnd = select_frnd()
    # Asking for the secret message
    user_message = raw_input("Enter your secret message: ")
    # Asking for name of image to be encoded with secret message
    original_image = raw_input("Enter the name of your image: ")
    output_path = "output.jpg"
    # Using encode() funtion from Steganography library to encrypt the message
    Steganography.encode(original_image, output_path, user_message)
    time = datetime.now()
    sent_by_me = True
    new_chat = ChatMessages(user_message, time, sent_by_me)
    # The message will be appended in ChatMessage class
    friends[selected_frnd].chats.append(new_chat)
    print "Message has successfully Encrypted at : " + time.strftime(
        "%a,%d %Y %H:%M:%S")
Beispiel #26
0
def read_message():
    sender = select_friend()
    output_path = ("output.jpg")
    get = Steganography.decode(output_path)
    print get
    new_chat = chat_message(get, False)
    friends[sender].chats.append(new_chat)
    print("your message has been sent")
Beispiel #27
0
def read_message():                                                                  # declare a function read_message to read a encypted message send by the friend
    sender = select_a_friend()
    output_path = raw_input(colored("what is the name of the file u want to decode? ","red"))
    secret_text = Steganography.decode(output_path)
    print colored("This is the secret message send by your friend" + " " + secret_text,"red")
    new_text =(secret_text.upper()).split()
    if 'SOS' in new_text or 'ALERT' in new_text or 'HELP' in new_text:
        print colored("I am fine,we will meet Tommorow","blue")
Beispiel #28
0
def send_message():

    friend_choice = select_a_friend()

    original_image = raw_input("What is the name of the image?")
    output_path = "output.jpg"
    text = raw_input("What do you want to say? ")
    if len(text):
        Steganography.encode(original_image, output_path, text)

        new_chat = ChatMessage(text,True)

        friends[friend_choice].chats.append(new_chat)

        print "Your secret message image is ready!"
    else:
        print "no message to encode"
Beispiel #29
0
def read_message():  #  function for reading message
    selected_friend = select_frnd()  #  calling select_friend function
    output_path = raw_input("Which image you want to decode? ")  #  the name of image to be decoded
    secret_text = Steganography.decode(output_path)  #  calling decode() function to decode
    print "The decoded message is "+secret_text  #  printing the secret text
    #  class to store details of message
    new_chat = Chats(secret_text,False)
    friends[selected_friend]['chats'],append(new_chat)
Beispiel #30
0
 def calcAverageWords(self):
     #Average Words Spoken
     avg=0
     if len(self.chat)!=0:
         for i in self.chat:
             avg=avg+len(Steganography.decode(i.Message))
         avg=avg/(len(self.chat))
     print "Average Words Spoken: ",avg
def read_message():

    select = select_friend()
    image = raw_input("Name of the image in which message is hidden")
    msg = Steganography.decode(image)

    new_chat = {"message": msg, "time": datetime.now(), "sent_by_me": False}
    spy_add[select].chats.append(new_chat)
Beispiel #32
0
def send_message():

    # making user choose the friend to send message
    friend_choice = select_friend()

    # implementing steganography encoding message
    original_image = raw_input("What is the name of the image?")
    output_path = raw_input("What name do you want for image your friend receive?")
    text = raw_input("What do you want to say?")
    Steganography.encode(original_image, output_path, text)

    new_chat = ChatMessage(text, True)

    # saving the text message sent by user to corresponding friend
    friends[friend_choice].chats.append(new_chat)

    print "Your secret message image is ready!"
Beispiel #33
0
def read_a_message():
    selected_friend=select_a_frnd()
    output_path=raw_input('Which image you want to decode? ')
    secret_text=Steganography.decode(output_path)#decoding the message
    print'Secret text is:'+secret_text
    new_chat=ChatMessage(secret_text,False)
    friends[selected_friend].chats.append(new_chat)
    print'Your secret message has been saved..'
Beispiel #34
0
def read_a_message():
    sender = select_a_friend()
    output_path = raw_input("what is the name of the image.")
    secret_text = Steganography.decode(output_path)
    chat = chatmessage(secret_text, False)
    friends[sender].chat.append(chat)
    if secret_text.upper() == "SOS" or secret_text.upper() == "SAVE ME" or secret_text.upper() == "HELP":
        print("you will receive help soon...")
    print("your secret message is saved.")
def read_message():
    frnd = select_friend()
    sender = frnd
    avgg = 0
    flag = 0
    while True:
        output_path = raw_input('Name of image which contains secret message:')
        pattern = '^[a-zA-Z0-9\s]+\.jpg$'
        if re.match(pattern, output_path) != None:
            # Handling I/O error
            try:
                # Decryption of encrypted image
                secret_text = Steganography.decode(output_path)
                pattern = '^[a-zA-z]+$'
                # Handling cases of image having no secret message.
                if re.match(pattern, secret_text)!= None:
                    print 'This is your message:'
                    print secret_text
                    avg = len(secret_text)
                    new_chat = ChatMessage(secret_text, False, avg, sender)
                    friends[frnd].chats.append(new_chat)
                    print "Your secret message has been saved!"
                    break
                else:
                    print 'This file doesn\'t contain any secret message.'
                    print 'Try again.'
            except IOError:
                print 'No such file present in the directory.'
        else:
            print 'Invalid image name.. '
            print 'It must end with .jpg association.'
            print 'Try Again!'
            sleep(0.8)
        if new_chat.sender == 1:
            flag += 1
            av = len(new_chat.message) / flag
            avgg = avgg + av
            if avgg > 100:
                friends.pop(new_chat.sender)
                print 'He has been removed.'
                print 'He has been speaking too much.'
# Demo of Steganography

from steganography.steganography import Steganography

fo = open("messages.txt", "r")
lines = fo.readlines()

counter = 1
for line in lines:
    original_image = "original_images\\%d.jpg"%(counter)
    output_image = "encrypted_images\\secret%d.jpg"%(counter)
    message = line
    Steganography.encode(original_image, output_image, message)
    print("%d Successful"%(counter))
    counter += 1