-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_message.py
40 lines (36 loc) · 1.48 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
from select_friend import select_friend
from steganography.steganography import Steganography
from datetime import datetime
from globals import friends
import re
from colorama import init,Fore
init()
image_pattern="^[a-zA-Z0-9]+.jpg$"
def read_message():
# choose friend from the list
sender = select_friend()
if (sender == -1):
print Fore.RED + "Wrong Choice" + Fore.RESET
else:
friends[sender].avgChatWords()
while (True):
encrypted_image = raw_input("Please provide the encryted image to decode")
if re.match(image_pattern, 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
#saves the messages
new_chat = {
"message": encrypted_image,
"time": datetime.now(),
"sentby": False
}
friends[sender].chat.append(new_chat)
print Fore.GREEN + "Messages saved"
except IOError:
print Fore.RED + "Sry either image is not available or the image does not contain any valid message" + Fore.RESET
except TypeError:
print Fore.RED + "Sry either image is not available or the image does not contain any valid message" + Fore.RESET