Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from spy_details import spy, Spy, ChatMessage, friends, STATUS_MESSAGES, \
- block_menu, friends_menu, menu_choices, block_list
- from steganography.steganography import Steganography
- from datetime import datetime
- import getpass
- from termcolor import colored, cprint
- """ This program is used to send and receive secret messages """
- """ The default password for existing user(Mr. Gaur) is 'lessordinary """
- begin = 'Press any key to open the application'
- any_key = raw_input(begin)
- print 'The game is ON !!!'
- # Asking the user to create a new account or continue as existing user
- question = 'Do you want to continue as ' + spy.salutation + ' ' + spy.name + ' (Y/N)? '
- existing = raw_input(question)
- # To only receive input as 'Y' and 'N'
- while (existing.upper() != 'Y') and (existing.upper() != 'N'):
- print 'Invalid Input'
- existing = raw_input(question)
- # Function to start chat of spy with respect to the credentials provided
- def start_chat(spy):
- spy.name = spy.salutation + " " + spy.name
- # Test age of spy to be less than 50 and greater than 12
- if spy.age > 12 and spy.age < 50:
- password_test = getpass.getpass(prompt='Please enter your password again to continue ')
- # To check whether the password to the account is right or not
- while password_test != initial_password:
- print('The password is incorrect..!!!')
- password_test = getpass.getpass(prompt='Please enter the right password to continue ')
- else:
- print('\n')
- print 'Authentication complete. \nWelcome! ' + spy.name + ' \nAge: ' \
- + str(spy.age) + ' \nRating: ' + str(spy.rating) + ' \nSpy Chat mai aapka swaagat hai'
- show_menu = True
- while show_menu:
- menu()
- else:
- print 'Sorry you are not of the correct age to be a spy'
- # Function menu to take input from user for menu choices and act accordingly
- def menu():
- menu_choice = raw_input(menu_choices)
- if len(menu_choice) > 0:
- menu_choice = int(menu_choice)
- if menu_choice == 1:
- add_status()
- elif menu_choice == 2:
- friends_sub_menu()
- elif menu_choice == 3:
- send_message()
- elif menu_choice == 4:
- read_message()
- elif menu_choice == 5:
- read_chat_history()
- elif menu_choice == 6:
- print 'Application Closed'
- else:
- show_menu = False
- # Function add status to update status
- def add_status():
- updated_status_message = None
- if spy.current_status_message != None:
- print 'Your current status message is %s \n' % spy.current_status_message
- else:
- print 'You don\'t have any status message currently \n'
- default = raw_input("Do you want to select from the older status (y/n)? ")
- if default.upper() == "N":
- new_status_message = raw_input("What status message do you want to set? ")
- if len(new_status_message) > 0:
- STATUS_MESSAGES.append(new_status_message)
- updated_status_message = new_status_message
- elif default.upper() == 'Y':
- item_position = 1
- for message in STATUS_MESSAGES:
- print '%d. %s' % (item_position, message)
- item_position = item_position + 1
- message_selection = int(raw_input("\nChoose from the above messages "))
- if len(STATUS_MESSAGES) >= message_selection:
- updated_status_message = STATUS_MESSAGES[message_selection - 1]
- else:
- print 'The option you chose is not valid! Press either y or n.'
- if updated_status_message:
- print 'Your updated status message is: %s' % updated_status_message
- else:
- print "You current don't have a status update"
- return updated_status_message
- # Function Friends Sub Menu to deal with Friends Settings
- def friends_sub_menu():
- friends_menu_choice = raw_input(friends_menu)
- if len(friends_menu_choice) > 0:
- friends_menu_choice = int(friends_menu_choice)
- if friends_menu_choice == 1:
- number_of_friends = add_friend()
- print 'You have %d friends' % number_of_friends
- elif friends_menu_choice == 2:
- remove_friend()
- elif friends_menu_choice == 3:
- block_submenu()
- elif friends_menu_choice == 4:
- menu()
- else:
- print 'Invalid Entry'
- friends_sub_menu()
- # Function to select a friend to later apply various functions as needed
- def select_a_friend():
- item_number = 0
- for friend in friends:
- print '%d. %s %s aged %d with rating %.2f is online' % (item_number + 1, friend.salutation, friend.name,
- friend.age, friend.rating)
- item_number = item_number + 1
- friend_choice = raw_input("Choose from your friends")
- # '-1' because indexing starts from zero in list
- friend_choice_position = int(friend_choice) - 1
- return friend_choice_position
- # Function to add a new friend
- def add_friend():
- new_friend = Spy('', '', 0, 0.0, 0)
- new_friend.name = raw_input("Please add your friend's name: ")
- new_friend.salutation = raw_input("Are they Mr. or Ms.?: ")
- # To only input salutation as 'Mr' or 'Ms'
- while new_friend.salutation != 'Mr' and new_friend.salutation != 'Ms':
- print "Invalid Input" \
- "\nPlease enter either 'Mr' or 'Ms' (case sensitive)"
- new_friend.salutation = raw_input()
- new_friend.age = int(raw_input("Age?"))
- new_friend.rating = float(raw_input("Spy rating?"))
- if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
- friends.append(new_friend)
- print 'Friend Added!'
- else:
- print 'Sorry! Invalid entry. We can\'t add spy with the details you provided'
- return len(friends)
- # Function to remove friends you can't kill
- def remove_friend():
- friend_choice = select_a_friend()
- friend_choice_position = int(friend_choice) - 1
- # The selected friend is removed from the friend list permanently
- del friends[friend_choice_position]
- print 'Friend removed successfully'
- # Function block submenu created to block or unblock friends
- def block_submenu():
- block_menu_choice = raw_input(block_menu)
- if len(block_menu_choice) > 0:
- block_menu_choice = int(block_menu_choice)
- if block_menu_choice == 1:
- block_friend()
- elif block_menu_choice == 2:
- unblock_friend()
- elif block_menu_choice == 3:
- friends_sub_menu()
- elif block_menu_choice == 4:
- menu()
- else:
- print 'Invalid Entry\n Please enter a value between 1-4'
- block_submenu()
- # Function to block those annoying friends
- def block_friend():
- friend_choice = select_a_friend()
- friend_choice_position = int(friend_choice) - 1
- # The selected friend is removed from the friend list
- # and appended to the block list
- block_list.append(friends.pop(friend_choice_position))
- block_list.sort()
- print 'Friend blocked successfully'
- # Function to unblock a frenemy
- def unblock_friend():
- item_number = 0
- for friend in block_list:
- print '%d. %s %s aged %d with rating %.2f is online' % \
- (item_number + 1, friend.salutation, friend.name, friend.age, friend.rating)
- item_number = item_number + 1
- friend_choice = raw_input("Choose from your friends")
- friend_choice_position = int(friend_choice) - 1
- # The selected friend is removed from the block list
- # and appended to the friend list
- friends.append(block_list.pop(friend_choice_position))
- friends.sort()
- print 'Friend un-blocked successfully'
- # Send encoded messages to your friends
- 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? "
- "\nWarning: If length of text exceeds 100,"
- "\nyou will be removed\n")
- # To make sure message field is not blank
- while len(text) <= 0:
- text = raw_input("Message field can't be left blank. Please enter something\n")
- Steganography.encode(original_image, output_path, text)
- # Removing the friend if message length exceeds 100
- if len(text) > 100:
- del friends[friend_choice]
- print 'The friend has been removed for exceeding the text limit'
- # How to behave when special messages are sent or received
- if text == 'SOS':
- text = 'Bhai bacha le'
- elif text == 'MAYDAY':
- text = "We're screwed bro"
- new_chat = ChatMessage(text, True)
- friends[friend_choice].chats.append(new_chat)
- chat_length = len(friends[friend_choice].chats)
- # To provide the average length of word a spy has used
- spy.total_length_text = spy.total_length_text + len(text)
- average_text_length = spy.total_length_text/chat_length
- print 'The average text length of this user is ' + str(average_text_length)
- print "Your secret message image is ready!"
- # Read decoded messages from your friends
- 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!"
- # Read old chats and relish the memories
- def read_chat_history():
- read_for = select_a_friend()
- print '\n6'
- for chat in friends[read_for].chats:
- # Variables 'time' and 'color_name' created to provide colored outputs
- time = colored(chat.time.strftime("%H:%M"), 'blue')
- color_name = colored(friends[read_for].name, 'red')
- if chat.sent_by_me:
- print '[%s] %s: %s' % (time, colored('You said', 'red'), chat.message)
- else:
- print '[%s] %s said: %s' % (time, color_name, chat.message)
- # Initialize function start_chat(spy) if it's an existing user
- if existing.upper() == "Y":
- initial_password = 'lessordinary'
- start_chat(spy)
- else:
- # Ask for new account creation for new users
- spy = Spy('', '', 0, 0.0)
- spy.name = raw_input("Welcome to spy chat, you must tell me your spy name first: ")
- if len(spy.name) > 0:
- spy.salutation = raw_input("Should I call you Mr. or Ms.?: ")
- # To make sure salutation is either 'Mr' or 'Ms' only
- while spy.salutation != 'Mr' and spy.salutation != 'Ms':
- print "Invalid Input" \
- "\nPlease enter either 'Mr' or 'Ms' (case sensitive)"
- spy.salutation = raw_input()
- spy.age = int(raw_input("What is your age?"))
- spy.rating = float(raw_input("What is your spy rating?"))
- # Asking the new user to set a password for his account
- initial_password = getpass.getpass(prompt='Enter a password for your SpyChat account ')
- start_chat(spy)
- else:
- print 'Please add a valid spy name'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement