-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_message.py
52 lines (48 loc) · 2.11 KB
/
read_message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from steganography.steganography import Steganography
from select_friend import select_friend
from spy_details import friend_list
from datetime import datetime
import re
from emergency_message import emergency
from colorama import init,Fore
init()
imageexpr="^[a-zA-Z0-9]+.jpg$"
def read_message():
#chooose friend from the list
sender=select_friend()
if(sender=="error"):
print Fore.RED+"Wrong Choice"+Fore.RESET
else:
while(True):
encrypted_image=raw_input("Please provide the encryted image to decode")
if re.match(imageexpr,encrypted_image,flags=0)is not None:
break
else:
print Fore.RED+"Image name must be alpha numeric and image extension must be .jpg"+Fore.RESET
try:
secret_message=Steganography.decode(encrypted_image)
print "The secret message is: "+secret_message
# emergency messages
for i in emergency:
if i==secret_message.upper():
print Fore.RED+"Your emergency message has been handled"+Fore.RESET
chats=friend_list[sender].get_chats()
all_message=secret_message
for chat in chats:
if not chat['send_by_me']:
all_message=all_message+" "+chat['message']
avg_words=len(all_message.split())
if(avg_words>100):
print Fore.RED+"Error!! Spy speaking too much. Removing the spy from friend list...."+Fore.RESET
del friend_list[sender]
else:
print Fore.GREEN+"Hello you are speaking fine. your average words speaked till date is: " + str(avg_words)+Fore.RESET
new_chat = {
'message': secret_message,
'time': datetime.now(),
'send_by_me': False
}
friend_list[sender].get_chats().append(new_chat)
print Fore.GREEN+"Message saved"+Fore.RESET
except:
print Fore.RED+"Sry either image is not available or the image does not contain any valid message"+Fore.RESET