-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencode.txt
465 lines (381 loc) · 17.4 KB
/
encode.txt
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# 1 89 32 2 5 6 7 8 9 10 11 12 13 14 18
# 89 32 2 5 6 7 8 9 10 11 12 13 14 18 1
# public_key_5000.pem
from tkinter import filedialog
from tkinter import *
from stegano import lsb
import speech_recognition as sr
import cv2
import math
import os
import shutil
from time import *
from subprocess import call,STDOUT
import aesutil
import sys
from termcolor import cprint
from pyfiglet import figlet_format
import rsautil1
import base64
import PIL.Image as PILImage
from simple_colors import *
import time
from tkinter.filedialog import askopenfile
from gtts import gTTS
# Used to split string into parts.
def split_string(s_str,count=15):
per_c=math.ceil(len(s_str)/count)
c_cout=0
out_str=''
split_list=[]
for s in s_str:
out_str+=s
c_cout+=1
if c_cout == per_c:
split_list.append(out_str)
out_str=''
c_cout=0
if c_cout!=0:
split_list.append(out_str)
return split_list
# Used to count frames in Video
def countFrames():
cap = cv2.VideoCapture(f_name)
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
cprint(f"Total frame in video are : {length-1}",'blue')
return length
# Extract the frames
def frame_extraction(video):
if not os.path.exists("./tmp"):
os.makedirs("tmp")
temp_folder="./tmp"
cprint("[INFO] tmp directory is created",'green')
vidcap = cv2.VideoCapture(video)
count = 0
cprint("[INFO] Extracting frames from video \n Please be patient",'blue')
while True:
success, image = vidcap.read()
if not success:
break
cv2.imwrite(os.path.join(temp_folder, "{:d}.png".format(count)), image)
count += 1
cprint("[INFO] All frames are extracted from video",'green')
#Encrypt and encode text into frames
def encode_string(input_string,root="./tmp/"):
cprint("Select your encryption type \n 1) AES Encrypted {Symetric Encryption} \n 2) RSA Encrypted {Assysmetric Encryption}\n",'blue')
Encryption_Style=int(input(""))
if Encryption_Style == 1:
res=input_string
key123=int(input("Choose key type \n \n 2.ASCII : "))
key = input("Enter the key : ")
if key123==1:
input_string = aesutil.encrypt(key=key,source=res)
else:
input_string = aesutil.encrypt(key=key,source=res,keyType='ascii')
key_path = input("Enter the receiver publickey filename with path to encrypt key : ")
key_rsa = rsautil1.encrypt(message=key,key_path=key_path)
key_rsa = key_rsa.decode('utf-8')
print(f"Asymetric encrypted key to be shared with receiver \n {key_rsa}")
file_obj = open("./AES-ENC-Key/ReceiverKey.txt", "wb")
key_rsa = key_rsa.encode()
file_obj.write(key_rsa)
file_obj.close()
print(f"\n AES Encypted message: {input_string}")
split_string_list=split_string(input_string)
#print(split_string_list)
split_string_length = len(split_string_list)
FRAMES = list(map(int, input(f"Enter {split_string_length} FRAME NUMBERS seperated by space : ").split()))
frame_choice = int(input("1) Do you want to store frame numbers in an image \n 2) No! Don't store : "))
if frame_choice == 1:
ENCODE_IMAGE = input("Enter image name with extension : ")
res = str(FRAMES)
if key123==1:
FRAMES_ENCODED = aesutil.encrypt(key=key,source=res)
secret = lsb.hide(ENCODE_IMAGE,str(FRAMES_ENCODED))
secret.save("image-enc.png")
cprint("[Info] Frames numbers are hidden inside the image with filename image-enc.png",'red')
else:
FRAMES_ENCODED = aesutil.encrypt(key=key,source=res,keyType='ascii')
secret = lsb.hide(ENCODE_IMAGE,str(FRAMES_ENCODED))
secret.save("image-enc.png")
cprint("[Info] Frames numbers are hidden inside the image with filename image-enc.png",'red')
else :
cprint("[Info] Frame numbers are not stored anywhere. Please remember them.",'red')
else :
res=input_string
key_path = input("Enter the publickey filename with path : ")
input_string = rsautil1.encrypt(message=res,key_path=key_path)
input_string = input_string.decode('utf-8')
input_string = str(input_string)
print(f"Encypted message: \n {input_string}")
split_string_list=split_string(input_string)
#print(split_string_list)
split_string_length = len(split_string_list)
FRAMES = list(map(int, input(f"Enter {split_string_length} FRAME NUMBERS seperated by space : ").split()))
frame_choice = int(input("1) Do you want to store frame numbers in an image \n2) No! Don't store : "))
if frame_choice == 1:
ENCODE_IMAGE = input("Enter image name with extension : ")
res = str(FRAMES)
FRAMES_ENCODED = rsautil1.encrypt(message=res,key_path=key_path)
FRAMES_ENCODED = FRAMES_ENCODED.decode('utf-8')
secret = lsb.hide(ENCODE_IMAGE,str(FRAMES_ENCODED))
secret.save("image-enc.png")
cprint("[Info] Frames numbers are hidden inside the image with filename image-enc.png",'red')
#res = lsb.reveal("image-enc.png") #for debugging
#res = res.decode('utf-8')
#res = str(res)
#print(f"Encrypted frame numbers : {res}")
else :
cprint("[Info] Frame numbers are not stored anywhere. Please remember them.",'red')
for i in range(0,len(FRAMES)):
f_name="{}{}.png".format(root,FRAMES[i])
#print(f_name)
secret_enc=lsb.hide(f_name,split_string_list[i])
secret_enc.save(f_name)
cprint("[INFO] Frame {} holds {}".format(FRAMES[i],split_string_list[i]),'blue')
# delete temporary files
def clean_tmp(path="./tmp"):
if os.path.exists(path):
shutil.rmtree(path)
print("[INFO] tmp files are cleaned up")
def main():
ENCODE_CHOICE = int(input("Choose text or text from text document to hide inside image. \n Enter number either 1|2|3|4|5 : \n1.TEXT \n2.TEXT DOCUMENT \n3.Image Hide \n4.Audio Hide \n5.Video Hide \nEnter Your Choice : "))
# print("Enter Your Choice : ")
if ENCODE_CHOICE==1:
TEXT_TO_ENCODE = input("Enter the text to encrypt and encode : ")
countFrames()
frame_extraction(f_name)
encode_string(TEXT_TO_ENCODE)
# Mix images into video and add audio.
call(["ffmpeg", "-i",f_name, "-q:a", "0", "-map", "a", "tmp/audio.mp3", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
call(["ffmpeg", "-i", "tmp/%d.png" , "-vcodec", "png", "tmp/video.mov", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
call(["ffmpeg", "-i", "tmp/video.mov", "-i", "tmp/audio.mp3", "-codec", "copy", "video.mov", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
cprint("Video is succesfully encoded with encrypted text.",'green')
clean_tmp()
if ENCODE_CHOICE==2:
print("Please Select a Txt file as an Input")
FILE_TO_ENCODE = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("Text files","*.txt"),("all files","*.*")))
# FILE_TO_ENCODE = input("Select text from file:")
TEXT_TO_ENCODE = []
with open(FILE_TO_ENCODE) as f:
for lines in f:
TEXT_TO_ENCODE.append(lines)
TEXT_TO_ENCODE = str(TEXT_TO_ENCODE)
print(TEXT_TO_ENCODE)
countFrames()
frame_extraction(f_name)
encode_string(TEXT_TO_ENCODE)
# Mix images into video and add audio.
call(["ffmpeg", "-i",f_name, "-q:a", "0", "-map", "a", "tmp/audio.mp3", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
call(["ffmpeg", "-i", "tmp/%d.png" , "-vcodec", "png", "tmp/video.mov", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
call(["ffmpeg", "-i", "tmp/video.mov", "-i", "tmp/audio.mp3", "-codec", "copy", "video.mov", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
print(yellow('Video is succesfully encoded with encrypted text Document', ['bold']))
# cprint("Video is succesfully encoded with encrypted text.",'yellow')
clean_tmp()
if ENCODE_CHOICE==3:
# root=Tk()
FILE_TO_ENCODE= input("\n Enter image name with extension : ")
# FILE_TO_ENCODE = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("Image files","*.*"),("all files","*.*")))
img=cv2.imread(FILE_TO_ENCODE)
# img=cv2.resize(img,(1000,1000))
li=[]
# cv2.imshow("img",img)
# root.destroy()
# root.mainloop()
# .deiconify()
# print("Hello")
# cv2.waitKey(0)
# print("Hello2")
# root.mainloop()
for i in img:
for j in i:
for k in j:
li.append(k)
s=" ".join(str(x) for x in li)
print(s)
countFrames()
frame_extraction(f_name)
encode_string(s)
# Mix images into video and add audio.
call(["ffmpeg", "-i",f_name, "-q:a", "0", "-map", "a", "tmp/audio.mp3", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
call(["ffmpeg", "-i", "tmp/%d.png" , "-vcodec", "png", "tmp/video.mov", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
call(["ffmpeg", "-i", "tmp/video.mov", "-i", "tmp/audio.mp3", "-codec", "copy", "video.mov", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
print(yellow('Video is succesfully encoded with Image.', ['bold']))
# cprint("Video is succesfully encoded with encrypted text.",'yellow')
clean_tmp()
if ENCODE_CHOICE==4:
r=sr.Recognizer()
# print("1")
print(yellow('Audio Name Speech.wav is reading...', ['bold']))
with sr.AudioFile('speech.wav') as source:
audio_text = r.listen(source)
# print("1")
try:
text = r.recognize_google(audio_text)
# print('Converting audio transcripts into text ...')
print(text)
except:
print('Sorry.. run again...')
countFrames()
frame_extraction(f_name)
encode_string(text)
# print("Hurreg")
# Mix images into video and add audio.
call(["ffmpeg", "-i",f_name, "-q:a", "0", "-map", "a", "tmp/audio.mp3", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
call(["ffmpeg", "-i", "tmp/%d.png" , "-vcodec", "png", "tmp/video.mov", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
call(["ffmpeg", "-i", "tmp/video.mov", "-i", "tmp/audio.mp3", "-codec", "copy", "video.mov", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
cprint("Video is succesfully encoded with encrypted audio.",'green')
clean_tmp()
if ENCODE_CHOICE==5:
print("Be Patient for processing")
# vishal =Tk()
text1 = input("1.enter text to hide\n")
path = input("Enter path for audio file")
r=sr.Recognizer()
# # print("1")
# print(yellow('Audio Name Speech.wav is reading...', ['bold']))
with sr.AudioFile(path) as source:
audio_text = r.listen(source)
# print("1")
try:
text2 = r.recognize_google(audio_text)
# print('Converting audio transcripts into text ...')
print(text2)
except:
print('Sorry.. run again...')
path= input("\n Enter path for image : ")
img=cv2.imread(path)
# img=cv2.resize(img,(1000,1000))
li=[]
for i in img:
for j in i:
for k in j:
li.append(k)
text3=" ".join(str(x) for x in li)
path= input("\n Enter path for video : ")
cap = cv2.VideoCapture(path)
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
li=[]
count=0
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
frame = cv2.resize(frame, (300, 300))
# cv2.imshow('frame',frame)
# count+=1
# if(count%2==0):
# fp+=1
# for i in frame:
# for j in i:
# for k in j:
# li.append(k)
count+=1
if(count%48==0):
# 4 lakh
# fp+=1
for i in frame:
for j in i:
for k in j:
li.append(k)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
else:
break
text4=" ".join(str(x) for x in li)
print(text1)
sleep(1)
print(text2)
sleep(1)
print(text3)
sleep(1)
print(text4)
s=text1+"*"+text2+"*"+text3+"*"+text4
# r=sr.Recognizer()
# # print("1")
# print(yellow('Audio Name Speech.wav is reading...', ['bold']))
# with sr.AudioFile('speech.wav') as source:
# audio_text = r.listen(source)
# # print("1")
# try:
# text = r.recognize_google(audio_text)
# # print('Converting audio transcripts into text ...')
# print(text)
# except:
# print('Sorry.. run again...')
countFrames()
frame_extraction(f_name)
encode_string(s)
# print("Hurreg")
# Mix images into video and add audio.
call(["ffmpeg", "-i",f_name, "-q:a", "0", "-map", "a", "tmp/audio.mp3", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
call(["ffmpeg", "-i", "tmp/%d.png" , "-vcodec", "png", "tmp/video.mov", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
call(["ffmpeg", "-i", "tmp/video.mov", "-i", "tmp/audio.mp3", "-codec", "copy", "video.mov", "-y"],stdout=open(os.devnull, "w"), stderr=STDOUT)
cprint("Video is succesfully encoded with encrypted Video.",'green')
clean_tmp()
# FILE_TO_ENCODE= input("\n Enter image name with extension : ")
# FILE_TO_ENCODE = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("Image files","*.*"),("all files","*.*")))
# # print("Succ")
# # Language in which you want to convert
# language = 'en'
# myobj = gTTS(text=FILE_TO_ENCODE, lang=language, slow=False)
# print("Succ1")
# # img=cv2.imread(FILE_TO_ENCODE)
# # Saving the converted audio in a mp3 file named
# # welcome
# myobj.save("welcome1.mp3")
# print("Succ2")
# Playing the converted file
# os.system("welcome.mp3")
# r = sr.Recognizer()
# with sr.AudioFile('spech.wav') as source:
# audio_text = r.listen(source)
# # recoginize_() method will throw a request error if the API is unreachable, hence using exception handling
# try:
# using google speech recognition
# text = r.recognize_google(audio_text)
# print('Converting audio transcripts into text ...')
# print(text)
# if ENCODE_CHOICE==6:
# print("Be Patient for processing")
# text1 = input("1.enter text to hide\n")
# print("Select file to hide audio")
# file = askopenfile(parent=vishal, mode='r+', title = "ADD DATA",filetype=[("audio file",".wav"),("ALL FILES", ".*")])
# r=sr.Recognizer()
# # print("1")
# print(yellow('Audio Name Speech.wav is reading...', ['bold']))
# with sr.AudioFile(file.name) as source:
# audio_text = r.listen(source)
# # print("1")
# try:
# text2 = r.recognize_google(audio_text)
# # print('Converting audio transcripts into text ...')
# print(text2)
# countFrames()
# frame_extraction(f_name)
# encode_string(s)
# print("Hurreg")
if __name__ == "__main__":
os.system('cls' if os.name == 'nt' else 'clear')
cprint(figlet_format('Group9', font='slant'),'yellow', attrs=['bold'])
# time.sleep(3)
print("\n")
print(green('Guide: Prof. (Dr.) Premanand P. Ghadekar', ['bold']))
# print("Guide: Prof. (Dr.) Premanand P. Ghadekar")
# time.sleep(2)
print("\n")
print(blue('Group Members', ['bold']))
# Prajwal Atram, Hitashri Patil, Nupur Shinde, Vishal Singh, Sameer Meshram
print("\n")
print("06 - Prajwal Atram")
print("40 - Hitashri Patil")
print("54 - Nupur Shinde")
print("63 - Vishal Singh")
print("76 - Sameer Meshram")
print("\n\n")
time.sleep(2)
print(yellow('Video Steganography', ['bold']))
print("\n\n")
cprint(figlet_format('AES & RSA encrytion', font='digital'),'green', attrs=['bold'])
f_name = sys.argv[1]
#image_name = sys.argv[2]
main()