-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCODE.py
793 lines (584 loc) · 29.5 KB
/
CODE.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
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
import tkinter as tk # python 3
from tkinter import font as tkfont # python 3
#import Tkinter as tk # python 2
#import tkFont as tkfont # python 2
from tkinter import *
from tkinter import *
from tkinter import filedialog
import cv2
from tkinter import ttk
import os
from PIL import Image
import subprocess
import cv2
import os
from PIL import Image
import subprocess
import shutil
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
self.grid()
self.geometry("800x600")
self.resizable(width=False, height=False)
self.title("Steganography")
self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self,bg="black")
container.pack(fill=BOTH, expand=YES)
# # container.pack(side=",top", fill="both", expand=True)
# container.grid_rowconfigure(0, weight=1)
# container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.parent = parent
parent.grid_columnconfigure(0,weight=1)
parent.grid_rowconfigure(0, weight=1)
self.configure(bg="black")
B1 = Button(self, text="Encode", command=lambda: controller.show_frame("PageOne"))
B1.place(relx=0.262, rely=0.405, height=43, width=136)
B1.configure(bg="black")
B1.configure(font=("Courier", 20,'bold'))
B1.configure(fg="white")
B2 = Button(self, text="Decode", command=lambda: controller.show_frame("PageTwo"))
B2.configure(bg="black")
B2.configure(foreground="white")
B2.configure(font=("Courier", 20,'bold'))
B2.place(relx=0.54, rely=0.405, height=43, width=136)
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.parent = parent
parent.grid_columnconfigure(0, weight=1)
parent.grid_rowconfigure(0, weight=1)
# self.pack(fill=BOTH, expand=YES)
self.configure(bg="black")
self.label1 = Label(self, text="Choose Video")
self.label1.place(relx=0.180, rely=0.350, height=34, width=142)
self.label1.configure(bg="black")
self.label1.configure(font=("Courier", 15,'bold'))
self.label1.configure(foreground="white")
self.label2 = Label(self, text="Input Text")
self.label2.place(relx=0.183, rely=0.489, height=34, width=138)
self.label2.configure(bg="black")
self.label2.configure(font=("Courier", 15,'bold','italic'))
self.label2.configure(fg="green2")
self.entry1 = Entry(self)
self.entry1.place(relx=0.383, rely=0.356, height=24, relwidth=0.34)
self.entry1.configure(background="white")
self.entry1.configure(foreground="black")
self.entry2 = Entry(self)
self.entry2.place(relx=0.383, rely=0.489, height=24, relwidth=0.34)
self.entry2.configure(background="white")
self.entry2.configure(foreground="black")
self.button1 = Button(self, text="Browse", command=self.callback)
self.button1.place(relx=0.75, rely=0.356, height=33, width=69)
self.button1.configure(font=("Courier", 10))
self.button1.configure(bg="black")
self.button1.configure(foreground="white")
self.button2 = Button(self, text="Encode", command=self.encode)
self.button2.place(relx=0.500, rely=0.689, height=37, width=78)
self.button2.configure(background="black")
self.button2.configure(font=("Courier", 10))
self.button2.configure(foreground="white")
self.button3 = tk.Button(self, text="Back", command=lambda: controller.show_frame("StartPage"))
self.button3.place(relx=0.0, rely=0.0, height=33, width=69)
self.button3.configure(bg="black")
self.button3.configure(font=("Courier", 10))
self.button3.configure(fg="white")
#################################################################
def frame_to_images(self,video):
folder = 'VSJH_IMAGES'
os.makedirs(folder, exist_ok=True)
vidcap = cv2.VideoCapture(video)
cnt = 0
while True:
success, arrayframe = vidcap.read()
if not success:
break
cv2.imwrite(os.path.join(folder, "{:d}.png".format(cnt)), arrayframe)
cnt += 1
def fti(self,video):
folder = 'VSJH_ORI'
os.makedirs(folder, exist_ok=True)
vidcap = cv2.VideoCapture(video)
cnt = 0
while True:
success, arrayframe = vidcap.read()
if not success:
break
cv2.imwrite(os.path.join(folder, "{:d}.png".format(cnt)), arrayframe)
cnt += 1
def popupmsg(self):
popup = tk.Tk()
popup.wm_title("!")
label = ttk.Label(popup, text="Invalid Input", font=("Courier", 10))
label.pack(side="top", fill="x", pady=10)
B1 = ttk.Button(popup, text="Okay", command=popup.destroy)
B1.pack()
popup.mainloop()
def encode(self):
send_lis = []
input_string = self.entry2.get()
video_path = self.entry1.get()
self.fti(video_path)
print("INput : Sytring -------------------> "+input_string)
if len(input_string)==0:
self.popupmsg()
if len(video_path)==0:
self.popupmsg()
input_video_path = ""
for i in video_path:
if i is '/':
#print("q")
input_video_path +='\\\\'
else:
input_video_path += i
print(input_video_path)
self.frame_to_images(input_video_path)
# print("FRAMES TO IMAGES COMPLETED.")
vidObj = cv2.VideoCapture(input_video_path)
length = int(vidObj.get(cv2.CAP_PROP_FRAME_COUNT))
# print("Number of Frames : "+" "+str(length))
# print(s)
s = []
s.append(len(input_string))
for i in range(0, len(input_string)):
s.append(ord(input_string[i]))
slis = set()
lis = []
seed = int(0)
# /////////////////////////////////////////////////////////////////////
# FINDING INITIAL SEED BY ADDING ALL R,G,B VALUES FROM FIRST FRAME.
psframe = Image.open(str("VSJH_IMAGES") + "\\" + str(0) + ".png")
width, height = psframe.size
# print("width : "+str(width)+" height : "+str(height))
for row in range(0, width - 1):
for column in range(0, height - 1):
x, y, z = psframe.getpixel((row, column))
seed += int(int(x) + int(y) + int(z))
seed = seed % 179
print("SEED : "+str(seed))
# /////////////////////////////////////////////////////////////////////
seed_saved = int(seed) # SEED SAVED WHICH CAN GIVE THE SEQUENCE.
m = int(length) # M IS THE NUMBER OF FRAMES OF THE VIDEO.
seed, slis, lis = self.next_seed(seed, m, slis, lis) # FIRST SEED IS GENERATED FOR
# print("First frame" + " " + str(seed))
#seed_saved=int(seed)
psframe = Image.open(str("VSJH_IMAGES") + "\\" + str(seed) + ".png")
width, height = psframe.size
n1 = int((width - 1) / 2) # GOTO MIDDLE POSITION OF FIRST FRAME FROM THE SEQUENCE TO FIND NUMBER OF HOPS.
n2 = int((height - 1) / 2)
r, g, b = psframe.getpixel((n1, n2))
next_hop = (r + g + b) % 9 + 1
lis.clear() # NOW WE GOT FIRST HOP AS WELL AS THE SEED SO EMPTY THE LIST AND SET.
slis.clear()
seed = seed_saved # INITIALIZE SEED TO ACTUAL SEED VALUE.
xcor = int(width / 2) # INITIALLY POSITION OF XCOR AND YCOR IS MIDDLE.
ycor = int(height / 2)
prevxcor = int(xcor)
prevycor = int(ycor)
# print("XCOR :: " + str(xcor) + " YCOR :: " + str(ycor))
# print("INITIAL XCOR AND YCOR : " + " " + str(xcor) + " " + str(ycor))
for idx in range(0, len(s)): # ITERATE LOOP FOR PUTTING IDX NUMBER OF CHARACTERS
for __ in range(0, next_hop): # SKIP X = NUMBER OF HOPS, FRAMES BY TAKING VALUE OF NEXT XCOR
seed, slis, lis = self.next_seed(seed, m, slis, lis)
psframe = Image.open(str("VSJH_IMAGES") + "\\" + str(seed) + ".png")
width, height = psframe.size
xtrav = xcor
ytrav = ycor
next_xcor = ""
next_ycor = ""
for i in range(1, 16): # FINDING NEXT X COORDINATE
xtrav += 1
xtrav = xtrav % width
r, g, b = psframe.getpixel((xtrav, ytrav))
if r % 2 == 0:
next_xcor += '0'
else:
next_xcor += '1'
for i in range(1, 16): # FINDING NEXT Y COORDINATE
ytrav -= 1
ytrav = ytrav % height
r, g, b = psframe.getpixel((xtrav, ytrav))
if r % 2 == 0:
next_ycor += '0'
else:
next_ycor += '1'
prevxcor = xcor
prevycor = ycor
xcor = int(next_xcor, 2) % width
ycor = int(next_ycor, 2) % height
print("XCOR :: " + str(xcor) + " YCOR :: " + str(ycor))
seed, slis, lis = self.next_seed(seed, m, slis, lis) # FRAME TO INSERT THE DATA.
psframe = Image.open(str("VSJH_IMAGES") + "\\" + str(seed) + ".png")
width, height = psframe.size
val = s[idx]
val_str = self.binary(val)
xflg = int(0)
yflg = int(0)
diff = int(1000000007)
for i in range(0, width - 1): # FINDING XFLG AND YFLG TO INSERT DATA INTO FRAME IN 3,3,2 FORMAT.
for j in range(0, height - 1):
rr, gg, bb = psframe.getpixel((i, j))
rstr = self.binary(rr)
gstr = self.binary(gg)
bstr = self.binary(bb)
if rstr[5:] == val_str[0:3] and gstr[5:] == val_str[3:6] and bstr[6:] == val_str[6:]:
xflg = i
yflg = j
break
else:
string = rstr[5:] + gstr[5:] + bstr[6:]
val_string = int(string, 2)
if (int(abs(val_string - val)) < int(diff)):
diff = abs(val_string - val)
xflg = i
yflg = j
xcor = xflg
ycor = yflg
r, g, b = psframe.getpixel((xflg, yflg)) # GET VAL OF THE COORDINATE TO CHANGE IT.
rchstr = self.binary(r)
gchstr = self.binary(g)
bchstr = self.binary(b)
rchstr = rchstr[5:] + val_str[0:3] # CHANGING VALUE OF THE PIXEL BY OUR DATA.
gchstr = gchstr[5:] + val_str[3:6]
bchstr = bchstr[6:] + val_str[6:]
r = int(rchstr, 2) # NEW PIXEL VALUES AS OUR DATA.
g = int(gchstr, 2)
b = int(bchstr, 2)
encoded = psframe.copy() # TIME TO PUT THIS INTO FRAME
print("FRAME : " + str(seed) + " Co ordinates : " + str(xflg) + " "
+ str(yflg) + " DATA : " + str(s[idx]) )
encoded.putpixel((xflg, yflg), (r, g, b)) # CHANGE SUCCESSFUL
# send_lis.append(seed)
encoded.save(str("VSJH_IMAGES") + "\\" + str(seed) + ".png", compress_level=0) # SAVING THE FRAME.
r, g, b = encoded.getpixel((xflg, yflg))
next_hop = (r + g + b) % 9 + 1 # FINDING NEXT NUMBER OF HOPS.
print("Next number of hops : " + str(next_hop))
frame_num = lis[-2] # OPENING PREVIOUS FRAME
psframe = Image.open(str("VSJH_IMAGES") + "\\" + str(frame_num) + ".png")
encoded = psframe.copy()
xtrav = prevxcor
ytrav = prevycor
xcorstr = self.Binary(xflg)
ycorstr = self.Binary(yflg)
while len(xcorstr) < 15: # CREATING BINARY STRING OF X AND Y CORDINATES
xcorstr = '0' + xcorstr
while len(ycorstr) < 15:
ycorstr = '0' + ycorstr
for i in range(1, 16):
xtrav += 1
xtrav = xtrav % width
r, g, b = psframe.getpixel((xtrav, ytrav))
r = self.binary(r)
r = r[:7] + xcorstr[i - 1]
r = int(r, 2)
encoded.putpixel((xtrav, ytrav), (r, g, b))
for i in range(1, 16):
ytrav -= 1
ytrav = ytrav % height
r, g, b = psframe.getpixel((xtrav, ytrav))
r = self.binary(r)
r = r[:7] + ycorstr[i - 1]
r = int(r, 2)
encoded.putpixel((xtrav, ytrav), (r, g, b))
prevxcor = int(xcorstr, 2) % width
prevycor = int(ycorstr, 2) % height
print("------>>>>>>>>"+str(frame_num))
send_lis.append(frame_num)
encoded.save(str("VSJH_IMAGES") + "\\" + str(frame_num) + ".png", compress_level=0)
vidObj.release()
cv2.destroyAllWindows()
#self.merge(input_video_path)
print("----------------------------------------------------------------------------------")
print("SEND_LIS IS HERE GRAB IT !!!")
print(send_lis)
print("WIDTH IS HERE : ")
print(width)
print("HEIGHT IS HERE : ")
print(height)
print("----------------------------------------------------------------------------------")
def merge(self,input_video_path): # CHECK PATH AND DIRECTORIES OF COMMANDS.
command4 = "ffmpeg -framerate 30 -i VSJH_IMAGES\\%d.png -c:v huffyuv -pix_fmt rgb24 VSJH_IMAGES\\mute_video.mkv "
subprocess.call(command4, shell=True)
command1 = "ffmpeg -i " + input_video_path + " -ab 160k -ac 2 -ar 44100 -vn VSJH_IMAGES\\MiniAudio.wav"
subprocess.call(command1, shell=True)
os.makedirs("Stego_Video", exist_ok=True)
command3 = "ffmpeg -i VSJH_IMAGES\\mute_video.mkv -i VSJH_IMAGES\\MiniAudio.wav -c copy -map 0:v -map 1:a Stego_Video\\StegoVideo.mkv"
subprocess.call(command3, shell=True)
dirpath = os.getcwd()
shutil.rmtree(dirpath + "\\VSJH_IMAGES")
def callback(self):
path = filedialog.askopenfilename()
#self.entry1.delete(0, END) # Remove current text in entry
self.entry1.insert(0, path) # Insert the 'path'
def Binary(self,n): # FUNCTION TO RETURN BINARY FORMAT OF ANY NUMBER.
s = bin(n)
return s[2:]
def binary(self,n): # FUNCTION TO RETURN BINARY FORMAT OF NUMBER LESS THAN 256 IN 8 BITS FORMAT.
s = bin(n)
s = s[2:]
while len(s) < 8:
s = '0' + s
return s # BOTH FUNCTIONS ARE NECESSARY.
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
def next_seed(self,seed, m, slis, lis):
a = int(1237403)
b = int(3220093)
seed = (a * seed + b) % (m - 1)
seed += 1
lprev = int(len(slis))
slis.add(seed)
if lprev == len(slis):
for j in range(1,m):
lprev = (len(slis))
seed = j
slis.add(seed)
if (lprev != len(slis)):
lis.append(seed)
break
else:
lis.append(seed)
return seed, slis, lis
class PageTwo(tk.Frame):
def callback(self):
path = filedialog.askopenfilename()
#self.entry1.delete(0, END) # Remove current text in entry
self.entry1.insert(0, path) # Insert the 'path'
def Binary(self,n): # FUNCTION TO RETURN BINARY FORMAT OF ANY NUMBER.
s = bin(n)
return s[2:]
def binary(self,n): # FUNCTION TO RETURN BINARY FORMAT OF NUMBER LESS THAN 256 IN 8 BITS FORMAT.
s = bin(n)
s = s[2:]
while len(s) < 8:
s = '0' + s
return s # BOTH FUNCTIONS ARE NECESSARY.
def frame_to_images(self,video):
folder = 'VSJH_IMAGES'
os.makedirs(folder, exist_ok=True)
vidcap = cv2.VideoCapture(video)
cnt = 0
while True:
success, arrayframe = vidcap.read()
if not success:
break
cv2.imwrite(os.path.join(folder, "{:d}.png".format(cnt)), arrayframe)
cnt += 1
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
def next_seed(self,seed, m, slis, lis):
a = int(1237403)
b = int(3220093)
seed = (a * seed + b) % (m - 1)
seed += 1
lprev = int(len(slis))
slis.add(seed)
if lprev == len(slis):
for j in range(1,m):
lprev = (len(slis))
seed = j
slis.add(seed)
if (lprev != len(slis)):
lis.append(seed)
break
else:
lis.append(seed)
return seed, slis, lis
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
def decode(self): # def decode(length):
video_path = self.entry1.get()
if len(video_path) == 0:
self.popupmsg()
path = ""
for i in video_path:
if i == "/":
path += "\\\\"
else:
path += i
print(path)
self.frame_to_images(path) # CONVERT THE STEGO VIDEO TO FRAMES
# print("FRAMES TO IMAGES COMPLETED.")
vidObj = cv2.VideoCapture(path)
length = int(vidObj.get(cv2.CAP_PROP_FRAME_COUNT)) # CALCULATE THE NUMBER OF FRAMES IN STEGO VIDEO
# print("Number of Frames : "+" "+str(length))
dslis = set()
dlis = []
seed = int(0)
# /////////////////////////////////////////////////////////////////////
# FINDING INITIAL SEED BY ADDING ALL R,G,B VALUES FROM FIRST FRAME.
psframe = Image.open(str("VSJH_IMAGES") + "\\" + str(0) + ".png")
width, height = psframe.size
# print("width : "+str(width)+" height : "+str(height))
for row in range(0, width - 1):
for column in range(0, height - 1):
x, y, z = psframe.getpixel((row, column))
seed += int(int(x) + int(y) + int(z))
seed = seed % 179
print("DECODE : SEED : "+str(seed))
# /////////////////////////////////////////////////////////////////////
seed_saved = int(seed) # SEED SAVED WHICH CAN GIVE THE SEQUENCE.
m = int(length) # M IS THE NUMBER OF FRAMES OF THE VIDEO.
seed, dslis, dlis = self.next_seed(seed, m, dslis, dlis) # FIRST SEED IS GENERATED FOR
print("First frame" + " " + str(seed))
psframe = Image.open(str("VSJH_IMAGES") + "\\" + str(seed) + ".png")
width, height = psframe.size
n1 = int((width - 1) / 2) # GOTO MIDDLE POSITION OF FIRST FRAME FROM THE SEQUENCE TO FIND NUMBER OF HOPS.
n2 = int((height - 1) / 2)
r, g, b = psframe.getpixel((n1, n2))
next_hop = (r + g + b) % 9 + 1
dlis.clear() # NOW WE GOT FIRST HOP AS WELL AS THE SEED SO EMPTY THE LIST AND SET.
dslis.clear()
seed = seed_saved # INITIALIZE SEED TO ACTUAL SEED VALUE.
xcor = int(width / 2) # INITIALLY POSITION OF XCOR AND YCOR IS MIDDLE.
ycor = int(height / 2)
print("INITIAL XCOR AND YCOR : " + " " + str(xcor) + " " + str(ycor))
num_of_chars = int(0)
print("Number of chars : " + str(num_of_chars))
for idx in range(0, 1): # ITERATE LOOP FOR PUTTING IDX NUMBER OF CHARACTERS
for __ in range(0, next_hop): # SKIP X = NUMBER OF HOPS, FRAMES BY TAKING VALUE OF NEXT XCOR
seed, dslis, dlis = self.next_seed(seed, m, dslis, dlis)
psframe = Image.open(str("VSJH_IMAGES") + "\\" + str(seed) + ".png")
width, height = psframe.size
xtrav = xcor
ytrav = ycor
next_xcor = ""
next_ycor = ""
for i in range(1, 16): # FINDING NEXT X COORDINATE
xtrav += 1
xtrav = xtrav % width
r, g, b = psframe.getpixel((xtrav, ytrav))
if r % 2 == 0:
next_xcor += '0'
else:
next_xcor += '1'
for i in range(1, 16): # FINDING NEXT Y COORDINATE
ytrav -= 1
ytrav = ytrav % height
r, g, b = psframe.getpixel((xtrav, ytrav))
if r % 2 == 0:
next_ycor += '0'
else:
next_ycor += '1'
xcor = int(next_xcor, 2) % width
ycor = int(next_ycor, 2) % height
seed, dslis, dlis = self.next_seed(seed, m, dslis, dlis) # FRAME TO EXTRACT THE DATA.
psframe = Image.open(str("VSJH_IMAGES") + "\\" + str(seed) + ".png")
width, height = psframe.size
val_str = ""
r, g, b = psframe.getpixel((xcor, ycor)) # GET VAL OF THE COORDINATE TO CHANGE IT.
next_hop = (r + g + b) % 9 + 1
rchstr = self.binary(r)
gchstr = self.binary(g)
bchstr = self.binary(b)
val_str = val_str + rchstr[5:] # CHANGING VALUE OF THE PIXEL BY OUR DATA.
val_str = val_str + gchstr[5:]
val_str = val_str + bchstr[6:]
asciival = int(val_str, 2)
print("FRAME : " + str(seed) + " Co ordinates : " + str(xcor) + " "
+ str(ycor) + " DATA : " + chr(asciival) + str(asciival))
num_of_chars = int(asciival)
print("Number of chars :........................................................ " + str( num_of_chars ))
ans = []
for idx in range(0, num_of_chars): # ITERATE LOOP FOR PUTTING IDX NUMBER OF CHARACTERS
for __ in range(0, next_hop): # SKIP X = NUMBER OF HOPS, FRAMES BY TAKING VALUE OF NEXT XCOR
seed, dslis, dlis = self.next_seed(seed, m, dslis, dlis)
psframe = Image.open(str("VSJH_IMAGES") + "\\" + str(seed) + ".png")
width, height = psframe.size
xtrav = xcor
ytrav = ycor
next_xcor = ""
next_ycor = ""
for i in range(1, 16): # FINDING NEXT X COORDINATE
xtrav += 1
xtrav = xtrav % width
r, g, b = psframe.getpixel((xtrav, ytrav))
if r % 2 == 0:
next_xcor += '0'
else:
next_xcor += '1'
for i in range(1, 16): # FINDING NEXT Y COORDINATE
ytrav -= 1
ytrav = ytrav % height
r, g, b = psframe.getpixel((xtrav, ytrav))
if r % 2 == 0:
next_ycor += '0'
else:
next_ycor += '1'
xcor = int(next_xcor, 2) % width
ycor = int(next_ycor, 2) % height
seed, dslis, dlis = self.next_seed(seed, m, dslis, dlis) # FRAME TO EXTRACT THE DATA.
psframe = Image.open(str("VSJH_IMAGES") + "\\" + str(seed) + ".png")
width, height = psframe.size
val_str = ""
r, g, b = psframe.getpixel((xcor, ycor)) # GET VAL OF THE COORDINATE TO CHANGE IT.
next_hop = (r + g + b) % 9 + 1
rchstr = self.binary(r)
gchstr = self.binary(g)
bchstr = self.binary(b)
val_str = val_str + rchstr[5:] # CHANGING VALUE OF THE PIXEL BY OUR DATA.
val_str = val_str + gchstr[5:]
val_str = val_str + bchstr[6:]
asciival = int(val_str, 2)
print("FRAME : " + str(seed) + " Co ordinates : " + str(xcor) + " "
+ str(ycor) + " DATA : " + chr(asciival))
ans.append(asciival)
print("====================================================>> "+chr(asciival))
final_string = ""
for i in ans:
final_string += chr(i)
print(chr(i))
self.entry2.insert(0,final_string)
shutil.rmtree(os.getcwd()+"\\VSJH_IMAGES")
print("000000000000000000000000000000000000000000000000000000000000000000000000000")
def popupmsg(self):
popup = tk.Tk()
popup.wm_title("!")
label = ttk.Label(popup, text="Invalid Input", font=("Courier", 10))
label.pack(side="top", fill="x", pady=10)
B1 = ttk.Button(popup, text="Okay", command=popup.destroy)
B1.pack()
popup.mainloop()
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.controller = controller
self.parent = parent
parent.grid_columnconfigure(0, weight=1)
parent.grid_rowconfigure(0, weight=1)
if __name__ == "__main__":
app = SampleApp()
app.mainloop()