def read_message(): sender = select_a_friend() output_path = raw_input( "What is the name of the file you want to decode? ") try: #To decryept the message secret_text = Steganography.decode(output_path) print("Your secret message is:") print(secret_text) new_text = (secret_text.upper()).split() # To check the help or emergency message if 'SOS' in new_text or 'SAVE ME' in new_text or 'HELP ME' in new_text or 'ALERT' in new_text: print "Help me!!!!" print "Select the friend to send a helping message.\n" send_help_message() print "Message sent successfully to your frined...." new_chat = ChatMessage(secret_text, False) friends[sender].chats.append(new_chat) else: new_chat = ChatMessage(secret_text, False) friends[sender].chats.append(new_chat) print "Your secret message has been saved.\n" # No secret message except TypeError: print "\n Everything is okay...\nThere is no secret message in the image...."
def live_chat(sname): try: s = socket.socket() port = 12222 ip = '127.0.0.1' ch = input('PRESS \n 1. SERVER\n 2. CLIENT') if ch == 1: s.bind((ip, port)) s.listen(5) cname = raw_input('Enter friend name: ') c = None while True: if c is None: print 'waiting for friends...' c, addr = s.accept() else: print 'Response...' print c.recv(1025) q = raw_input('type msg here: ') c.send(q) chat_obj = ChatMessage(q, True) try: with open('chats.csv', 'ab') as chat_data: write = csv.writer(chat_data) write.writerow( [sname, cname, q, chat_obj.time, True]) print "Your secret message is ready!" except Exception as e: print e print 'exception in writing text to file' c.close() if ch == 2: s.connect((ip, port)) cname = raw_input('Enter friend name: ') while True: z = raw_input('Send Message :') s.send(z) chat_obj = ChatMessage(z, True) try: with open('chats.csv', 'ab') as chat_data: write = csv.writer(chat_data) write.writerow([sname, cname, z, chat_obj.time, True]) print "Your secret message is ready!" except Exception as e: print e print 'exception in writing text to file' print('Response...') print s.recv(1025) s.close() except Exception as e: print e
def read_message(): # Selecting the friend sender = select_a_friend() # Asking the name of image from where secret message is to be decoded output_path = raw_input( "What is the name of the file you want to decode? ") try: # Using decode() funtion with file name of encrypted message as parameter secret_text = Steganography.decode(output_path) print("Your secret message is:") print(secret_text) # Converting secret_text to uppercase new_text = (secret_text.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 "!" print "!" print "!" print "The friend who sent this message needs your help!" print "Please help your friend by sending a helping message...\n" print "Select the friend to send a helping message.\n" # Calling send_help_message() function to send the help send_help_message() # Message sent successfully print "You just sent a message to help your friend! " # Creating new chat new_chat = ChatMessage(secret_text, False) # Appending to chats friends[sender].chats.append(new_chat) # If there is no emergency messages or call for help else: new_chat = ChatMessage(secret_text, False) # Appending friends[sender].chats.append(new_chat) print "Your secret message has been saved.\n" # No message found exception except TypeError: print "Nothing to decode from the image...\n Sorry! There is no secret message"
def send_message(): friend_choice = friends[select_a_friend()].name original_image = raw_input("What is the name of the image?") #output.jpg is a output image, with output name output_path = 'output.jpg' text = raw_input("What do you want to say?") # encoding the message Steganography.encode(original_image, output_path, text) # the message will be stored in chat new_chat = ChatMessage(spy_name=spy_1.name, friend_name=friend_choice, time=datetime.now().strftime("%d %B %Y"), message=text) #append new_chat in chats list. chats.append(new_chat) print("your secret message is ready.") with open('chats.csv', 'a') as chats_data: writer = csv.writer(chats_data) writer.writerow([ new_chat.spy_name, new_chat.friend_name, new_chat.time, new_chat.message ])
def send_message(): try: friend_select = select_friend() if friend_select is not False: input_path = raw_input("Enter the full path of the image : ") output_path = raw_input( "Enter path where you want to store the output image : ") text = raw_input("Enter secret text that you want to encode : ") if name_valid(text) is True: if len(text.split()) > 100: print( "\033[1;34m You're speaking a lot, this is Intolerable!!\nYou're banished from the chat!! \033[1m;34m" ) del friends[friend_select] else: Steganography.encode(input_path, output_path, text) # VARIABLE TO STORE THE DETAILS OF THE NEW CHAT DATA new_chat = ChatMessage(text, True, 0) friends[friend_select].chats.append(new_chat) print("Your secret image is ready !") else: print( "\033[1;34m You haven't entered any secret message. Please try again! \033[1m;34m" ) except IOError: print( "\033[1;34m No such file or directory found!!\nEnter a valid path and try again!! \033[1m;34m" )
def read_message(): 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) friends[sender].chats.append(new_chat) print secret_text
def read_message(): # making user choose the friend to send message sender = select_friend() # impementing steganography decoding message output_path = raw_input("What is the name of the file?") secret_text = Steganography.decode(output_path) if str(secret_text).isspace(): print "This image contains no message!!" else: new_chat = ChatMessage(secret_text, False) # saving thereceived message from corresponding friend friends[sender].chats.append(new_chat) # checking for some specific words in message to generate special prompt if 'TTYL' in str(secret_text).upper(): print colored("Your Spy friend will 'Talk To You Later!'", 'red', attrs=['bold']) if 'SOS' in str(secret_text).upper(): print colored("Your spy friend is in extreme danger!! SAVE!", 'red', attrs=['bold']) if 'HELP' in str(secret_text).upper(): print colored("Your friend needs your HELP!!!", 'red', attrs=['bold']) if 'ON A MISSION' in str(secret_text).upper(): print colored("Your friend is on a Mission!!", 'red', attrs=['bold']) print "Your secret message has been saved!"
def load_chats(): with open('chats.csv', 'rb') as chat_data: read2 = csv.reader(chat_data) for friend in range(len(Friends)): for row in read2: chat = ChatMessage(spy_name=row[0], friend_name=row[1], message=row[2], time=row[3], sent_by_me=row[4]) Friends[friend].chats.append(chat)
def read_a_message(spy): show_menu = True while show_menu: print colored("which friend you want to communicate with?", "yellow") # checks if user has a friend or not index = select_a_friend(spy) if index < 0: show_menu = False else: sender = friends[index].name # sender stores index of friend whose message user want to read output_path = raw_input(colored("enter the name of the image you want to decode(.jpg format) : ", "yellow")) # checking if mentioned file exist in os or not if os.path.exists(output_path): # checking extension of image if its in jpg if os.path.splitext(output_path)[1] == ".jpg": text = Steganography.decode(output_path) # decode method of Steganography library will retrieve hidden secrete message in selected image print colored("your received text: " + text , "blue") if text in special_text: print colored("don't worry " + sender + "on the way to rescue you!!!", "green", attrs=['bold']) # storing chats in chatmessage chat = ChatMessage(sent_by_me=spy.name, friend_name=sender, time=datetime.now().strftime("%d %B %Y"), message=text) chats.append(chat) # writing chats in chats.csv with open("chats.csv", 'a') as chat_record: writer = csv.writer(chat_record) writer.writerow([chat.sent_by_me, chat.friend_name, chat.time, chat.message]) show_menu = False else: print colored("file not in .jpg format", "red") else: print colored("file does not exist", "red")
def send_a_message(spy): show_menu = True while show_menu: print colored("which friend you want to communicate with?", "yellow") index = select_a_friend(spy) # checks if user has a friend or not if index < 0: show_menu = False else: selected_friend = friends[index].name # selected_friend contains index of friend selected via select_a_friend function original_image = raw_input(colored("enter name of image you want to encode secret message with(.jpg format): ", "yellow")) # checking if mentioned file exist in os or not if os.path.exists(original_image): # checking extension of image if its in jpg if os.path.splitext(original_image)[1] == ".jpg": output_path = 'output.jpg' text = raw_input(colored("enter secret message you want to hide: ", "yellow")) if text in special_text: text = colored(text + ": its a emergency reach me as soon as possible!!", "red", attrs=['bold']) # encode method of Steganography library will hide secrete message in selected image Steganography.encode(original_image, output_path, text) # storing chats in chatmessage chat = ChatMessage(sent_by_me=spy.name, friend_name=selected_friend, time=datetime.now().strftime("%d %B %Y"), message=text) chats.append(chat) # writing chats in chats.csv with open("chats.csv", 'a') as chat_record: writer = csv.writer(chat_record) writer.writerow([chat.sent_by_me, chat.friend_name, chat.time, chat.message]) print colored("your secret message is sent", "blue") show_menu = False else: print colored("file not in .jpg format", "red") else: print colored("file does not exist", "red")
def read_message(): # Selecting a friend sender = select_a_friend() # Inputting name of file output_path = raw_input("What is the name of the file?") # Decoding the secret message secret_text = Steganography.decode(output_path) number_of_words = len(secret_text.split()) # Checking the number of words in incoming message if number_of_words > 100: # If number of words in message is greater than 100 , we delete the friend who sent it. print 'This friend talks too much, Unfriending!! ' del friends[sender] else: # Check for empty secret message if len(secret_text) > 0: # Checking for special cases of emergency if secret_text == "SOS" or secret_text == "SAVE ME" or secret_text == "HELP": print 'Immediate help required.' new_chat = ChatMessage(secret_text, False) friends[sender].chats.append(new_chat) print "Your secret message has been saved!" else: print 'Empty message'
def read_message(): 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) friends[sender]['chats'].append(new_chat) print "Your secret message has been saved!" def read_chat_history(): read_for = select_a_friend() print '\n6' for chat in friends[read_for].chats: if chat.sent_by_me: print '[%s] %s: %s' % (chat.time.strftime("%d %B %Y"), 'You said:', chat.message) else: print '[%s] %s said: %s' % (chat.time.strftime("%d %B %Y"), friends[read_for].name, chat.message)
def read_message(): #This function separates the hidden text from the image and displays it sender = select_a_friend() output_path = raw_input("Enter the file name!!") ext = '.jpg' output_path = output_path + ext secret_text = Steganography.decode(output_path) new_chat = ChatMessage(secret_text, False) friends[sender].chats.append(new_chat) #print "Your secret message has been saved!" #return secret_text if len(secret_text) == 0: print "There is nothing in the secret message" else: if secret_text == 'SOS' or secret_text == "Save me" or secret_text == "Help": print "Its an emergencyyyy!!" print "Your mate sent -" + secret_text else: print "You are good to go. Your secret message is given below :" print secret_text
def read_message(): sender = select_friend() secret_image = raw_input("Enter encrypted image :") secret_text = Steganography.decode(secret_image) new_chat = ChatMessage(secret_text, False) friends[sender].chats.append(new_chat) print 'Your secret message has been saved'
def send_message(): #call the fuction select_friend which returns the position of friend whom we want to send the message #store it in a variable friend_choise friend_choise = select_friend() #input original image upon which text will be encoded original_img = raw_input('What is the name of the image') #save the path of the ouput image which will carry our message in output_path variable output_path = 'output.jpg' #input and store secret message in variable text text = raw_input('What do you want to say?') #original img is the carrier and output path has hidden text in it Steganography.encode(original_img, output_path, text) #save the secret message alongwith the time at which it was send using class ChatMessage new_chat = ChatMessage(text, True) #append the message to the friend's chat instance friends[friend_choise].chats.append(new_chat) print 'you secret message image is ready'
def send_message(): friend_choice = select_a_friend() original_image = raw_input("\nWhat is the name of the image?") output_path = "output.jpg" default = raw_input("Do you want to select from the special messages (y/n)? ") if default.upper() == "N": text = raw_input("What do you want to say? ") elif default.upper() == "Y": item_position = 1 for message in SPECIAL_MESSAGES: print '%d. %s' % (item_position, message) item_position = item_position + 1 message_selection = int(raw_input("\nChoose from the above messages "))-1 if len(SPECIAL_MESSAGES) >= message_selection: if message_selection == 0: text = "This is an SOS" elif message_selection == 1: text = "Please Help Me!" 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!\n"
def send_message(): if (len(friends) > 0): friend_choice = select_a_friend() original_image = raw_input("*What is the name of the image: ") output_path = "Image.jpg" text = raw_input( "*What secret message do you want to send in that image: ") if len(text) <= 100: #encoding msg into the image. Steganography.encode(original_image, output_path, text) new_chat = ChatMessage(text, True) friends[friend_choice].chats.append(new_chat) print "\n-----***Your secret Message Image is sent to your online Friend***-----\n" else: print "You cannot send a message bigger than length 100...!! Try Again..!!\n" send_message() else: print "\nPlease add some Friends on Spychat....!!\n\n" yes_no = raw_input("So do you want to add Friends..(Y/N): ") if (yes_no.upper() == 'Y'): add_friend() else: print "-----@@@@Its totally Your Wish@@@@-----"
def send_message(): friend_choice = select_friend() print "index = " + str(friend_choice) original_image = raw_input( "What is the name of the image?" ) # Ask the user for the name of the image they want to encode the secret message with. output_path = "output.jpg" text = raw_input( "What do you want to say?" ) # Ask the user for the secret message they want to hide. list_of = text.split(" ") if len( list_of ) >= 100: #to maintain the average number of words(here I take 100) spoken by a spy everytime you receive a message from a particular spy. print "Message limit exceeded!Please enter text less than 100 words." else: print "your secret message has been ready!" Steganography.encode( original_image, output_path, text ) # Using the Steganography library hide the message inside the image new_chat = ChatMessage(text, True) friends[friend_choice].chats.append(new_chat)
def send_message(): friend_choice = select_a_friend() original_image = raw_input("Now tell me the name of the image") output_path = "output.jpg" #message you want to say to your friend text = raw_input("What message would you like to send??????? ") Steganography.encode(original_image, output_path, text) new_chat = ChatMessage(text, True) # your message is appended friends[friend_choice].chats.append(new_chat) #calculate average words spoken by a spy in order the record words = text.split() average = sum(len(word) for word in words) / len(words) average = float(average) print "Average number of words spoken by a spy is", average if len(text) > 0: print "Your secret message image is ready! Now the unauthorized users can't read your message" else: print "Please enter secret message....You can't go further!!!!!"
def read_message(): #function for message reading 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) friends[sender].chats.append(new_chat) print "Your secret message has been saved!"
def send_a_message(): friend_choice = friends[select_a_friend()].name 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 text in special_words: text = colored(text + ": IT'S EMMERGENCY!!", "red") #encoding the message Steganography.encode(original_image, output_path, text) # the message will be stored in chat message class new_chat = ChatMessage(spy_name=spy_1.name, friend_name=friend_choice, time=datetime.now().strftime("%d %B %Y"), message=text) # name of the friend along which we add message. chats.append(new_chat) print("your secret message is ready.") with open('chats.csv', 'a') as chats_data: writer = csv.writer(chats_data) writer.writerow([ new_chat.spy_name, new_chat.friend_name, new_chat.time, new_chat.message ])
def read_message(): #here we are selecting a friend to hich messages we want to read sender = select_a_friend() output_path = raw_input("What is the name of the file?") secret_text = Steganography.decode(output_path) if len(secret_text) > 0: special_words=['SOS','SAVE ME','NEED HELP'] if secret_text in special_words: print colored('its an emergency special words:'+ secret_text,'red') else: print 'message is : '+ secret_text # average word count words = secret_text.split() friends[sender].average=(float(friends[sender].average*len(friends[sender].chats)+len(words)))/(len(friends[sender].chats)+ 1) print "Average word count is: %.2f" % (friends[sender].average) new_chat = ChatMessage(secret_text,False) # append chat message to friends sender list friends[sender].chats.append(new_chat) print "Your secret message has been saved!" if len(secret_text.split()) > 150: print colored('you are speaking too much.we are deleting you','red') friends.pop(sender) else: print 'your message is empty'
def read_message(spy): try: friend_choice = select_friend() output_path = raw_input('Enter image path ') try: secret_text = Steganography.decode(output_path) new_chat = ChatMessage(spy_id=friends[friend_choice].id, friend_id=spy.id, message=secret_text,time= datetime.now().strftime("%b %d %Y %H:%M")) new_chat.save() friends[friend_choice].chats.append(new_chat) print "Your secret message is ready!" except IOError: print 'File Not Found' except: print 'Operation Unsuccessful'
def read_a_message(): #selecting friend sender = select_a_friend() #input path of image where encoded message is stored output_path = raw_input("What is the name of the file?") #decoding message and storing secret_text = Steganography.decode(output_path) #chcking if image contains some image and it is not more than 100 in words if len(secret_text) > 0 and len(secret_text) <= 100: #Searching if special words like 'SOS','SAVEME'are found in the message if re.search(r'SOS', secret_text): print "Something Special" elif re.search(r'SAVEME', secret_text): print "NEED HELPPPPPP!!" elif re.search(r'SNOOP', secret_text): print "Watching Secretly" elif re.search(r'Quilsing', secret_text): print "Secretly helps enemy" else: print "Message readed" print secret_text #if image contains message then store in the chat new_chat = ChatMessage(secret_text, False) friends[sender].chats.append(new_chat) print "Your secret message has been saved!" #delete spy if message is more than 100 words elif len(secret_text) > 100: del friends[sender] print "Deleting spy!!!Speaks too much!!!" #printed incase image contains no message else: print "Nothing to read in image"
def load_chats(): with open('chats.csv', 'rb') as chats_data: reader = csv.reader(chats_data) for row in reader: cm = ChatMessage(row[0], row[1]) chats.append(cm)
def send_message(): selected_friend = select_frnd() original_image = raw_input("What is the name of your image? ") output_path = "output.jpg" message = raw_input("What is your secret message? ") if len(message) == 0: print "please enter something " elif message == "sos" or "save me " or "help me" or "save me please": print "hold on" elif message == "False" or "hack" or "#" or "@" or "?": print "spychat aint free" #no such symbols should be accepted else: print"your message is accepted" \ Steganography.encode( original_image , output_path , message ) message_sent_to = friends[selected_friend].name print "Message Encrypted" new_chat = ChatMessage(spy.name, message_sent_to , message , True) friends[selected_friend].chat.append(new_chat) with open("chats.csv", "a") as chat1data: writer = csv.writer(chat1data) writer.writerow([spy.name, message_sent_to, new_chat.message, new_chat.time, new_chat.sent_by_me])
def send_message(): friend_choice = select_a_friend( ) #send to the select_a_friend function and storing the value in friend_choice variable if friend_choice + 1 <= len( friends): #check if the number enetered is a part of list or not original_image = raw_input( "What is the name of the image?" ) #stores te name and the pat of the image to be scripted output_path = 'output.jpg' #scripted image is stored in this variable text = raw_input( "What do you want to say? Word Limit-100") #secret text Steganography.encode(original_image, output_path, text) #the image is encoded using stegnography new_chat = ChatMessage( text, True) #meassge added to the chat as send by the user friends[friend_choice].chats.append( new_chat) #message appended in the chat of a particular friend print colored("Your secret message image is ready!", 'green') else: print colored("Invalid Input!!", 'red') #the serial number does not exist
def read_message(): chosen_frnd = select_frnd() output_path = raw_input("Name of the image to be decoded ") secret_text = Steganography.decode(output_path) new_chat = ChatMessage(spy.name, friends[chosen_frnd].name, secret_text, False) friends[chosen_frnd].chat.append(new_chat) print "Your secret message is " + secret_text
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}
def read_message(): # choose friend from the list to communicate sender = select_friend() with open('chats.csv', 'rb') as chat_data: reader = csv.reader(chat_data) for row in reader: print row encrypted_image = raw_input("Provide encrypted image : ") secret_message = Steganography.decode(encrypted_image) print "The secret message is ", print(colored(secret_message, 'red')) new = (secret_message.upper()).split() with open('chats.csv', 'wb') as chatdata: writer = csv.writer(chatdata) writer.writerow([secret_message]) if "SOS" in new or "SAVE" in new or "HELP" in new or "ACCIDENT" in new or "ALERT" in new: print(colored("!", 'grey', 'on_yellow')), print(colored("!", 'grey', 'on_yellow')), print(colored("!", 'grey', 'on_yellow')) print( colored("The friend who sent this message need your help.", 'cyan')) print( colored("You can help your friend by sending helping message.", 'cyan')) print(colored("Select the friend to send helping message", 'red')) print( colored("You just sent a message to help your friend.", 'magenta')) new_chat = ChatMessage(secret_message, False) friends[sender].chats.append(new_chat) print(colored("Your secret message has been saved.", 'cyan')) else: print(colored("This image has no secret message. No decoding"))