-
Notifications
You must be signed in to change notification settings - Fork 1
/
decodetext.py
205 lines (185 loc) · 7.17 KB
/
decodetext.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
##This File for Text and text Document read
from stegano import lsb
import cv2
import os
import sys
import aesutil
import shutil
import numpy as np
from termcolor import cprint
from pyfiglet import figlet_format
import rsautil1
from simple_colors import *
import time
os.system('cls' if os.name == 'nt' else 'clear')
cprint(figlet_format('Group9', font='slant'),'green', attrs=['bold'])
print(yellow('Video Steganography', ['bold']))
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)
cprint(figlet_format('AES & RSA encrytion', font='digital'),'green', attrs=['bold'])
ENCODED_VIDEO = sys.argv[1]
temp_folder = "tmp2"
frame_choice = int(input("1) Extract and enter frame numbers from image \n2) Enter frame numbers manually : \nEnter choice: "))
decoded = {}
if frame_choice == 1:
ENCODED_IMAGE = input("\n Enter image name with extension : ")
res = lsb.reveal(ENCODED_IMAGE)
print(f"Encrypted frame numbers : {res}")
cprint("Select your encryption type \n 1) AES Encrypted {Symetric Encryption} \n 2) RSA Encrypted {Assysmetric Encryption}",'blue')
Encryption_Style=int(input(""))
if Encryption_Style == 1:
key = input("Enter the asymetric key to create AES key : ")
key_rsa = rsautil1.decrypt(message=key)
key_rsa = key_rsa.decode('utf-8')
print(f"Asymetric decrypted key \n {key_rsa}")
key123=int(input("Choose key type to decrypt image \n 2.ASCII : "))
key = input("Enter the key to decrypt image : ")
if key123==1:
msg = aesutil.decrypt(key=key,source=res)
msg1 = msg.decode('utf-8')
cprint(f"Decoded image : \n {msg}",'green')
FRAMES = list(map(int, input("Enter Above FRAME NUMBERS seperated by space: ").split()))
else:
msg = aesutil.decrypt(key=key,source=res,keyType='ascii')
msg1 = msg.decode('utf-8')
cprint(f"Decoded image: \n {msg1}",'green')
FRAMES = list(map(int, input("Enter Above FRAME NUMBERS seperated by space: ").split()))
else :
cprint("Reading private key from keys \nfolder and trying to decrypt",'red')
msg1 = rsautil1.decrypt(message=res)
msg1 = msg1.decode('utf-8')
cprint(f"Decoded image: \n {msg1}",'green')
FRAMES = list(map(int, input("Enter Above FRAME NUMBERS seperated by space: ").split()))
else :
FRAMES = list(map(int, input("Enter FRAME NUMBERS seperated by space: ").split()))
cprint("Select your decryption type \n 1) AES Encrypted {Symetric Encryption} \n 2) RSA Encrypted {Assysmetric Encryption}",'blue')
Encryption_Style=int(input(""))
#print(FRAMES)
def createTmp():
if not os.path.exists(temp_folder):
os.makedirs(temp_folder)
def countFrames():
cap = cv2.VideoCapture(ENCODED_VIDEO)
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
return length
def decodeVideo(number_of_frames):
# First get the frame
cap = cv2.VideoCapture(ENCODED_VIDEO)
frame_number = -1
while(frame_number<=number_of_frames):
frame_number += 1
frame_file_name = os.path.join(temp_folder,f"{frame_number}.png")
encoded_frame_file_name = os.path.join(temp_folder,f"{frame_number}-enc.png")
# print(f"Frame number {frame_number}")
ret, frame = cap.read()
if frame_number in FRAMES:
cv2.imwrite(encoded_frame_file_name,frame)
clear_message = lsb.reveal(encoded_frame_file_name)
decoded[frame_number] = clear_message
cprint(f"Frame {frame_number} DECODED: {clear_message}",'yellow')
def clean_tmp(path="./tmp2"):
if os.path.exists(path):
shutil.rmtree(path)
cprint("[INFO] tmp files are cleaned up",'yellow')
def arrangeAndDecrypt():
res=""
if Encryption_Style == 1:
for fn in FRAMES:
res = res + decoded[fn]
cprint(f"Final string: {res}",'green')
key123=int(input("Choose key type \n 2.ASCII : "))
key = input("Enter the key : ")
if key123==1:
msg = aesutil.decrypt(key=key,source=res)
msg1 = msg.decode('utf-8')
# s=msg
# li=s.split(" ")
# result=[]
# a=[]
# b=[]
# print((li))
# c=0
# for i in range(154):
# for j in range(328):
# for k in range(3):
# b.append(int(li[c]))
# c+=1
# a.append(b)
# b=[]
# result.append(a)
# a=[]
# # ans=[]
# # for i in result:
# # for j in i:
# # for k in j:
# # ans.append(k)
# # print((ans))
# result=np.asarray(result)
# result=result.astype(np.uint8)
# # print(result.shape)
# print(type(result))
# cv2.imshow('avc',result)
# cv2.waitKey(0)
cprint(f"Decoded message: \n {msg}",'green')
clean_tmp()
else:
msg = aesutil.decrypt(key=key,source=res,keyType='ascii')
msg1 = msg.decode('utf-8')
# s=msg.decode()
# print(type(s))
# # print(s)
# li=[]
# li=s.split(" ")
# result=[]
# a=[]
# b=[]
# # print((li))
# c=0
# for i in range(154):
# for j in range(328):
# for k in range(3):
# b.append(int(li[c]))
# c+=1
# a.append(b)
# b=[]
# result.append(a)
# a=[]
# # ans=[]
# # for i in result:
# # for j in i:
# # for k in j:
# # ans.append(k)
# # print((ans))
# result=np.asarray(result)
# result=result.astype(np.uint8)
# # print(result.shape)
# print(type(result))
# cv2.imshow('avc',result)
# cv2.waitKey(0)
cprint(f"Decoded message: \n {msg1}",'red')
# msg1.save("output.mp3")
# Playing the converted file
# os.system("output.mp3")
clean_tmp()
else :
for fn in FRAMES:
res = res + decoded[fn]
cprint(f"Final string: {res}",'green')
cprint("Reading private key from keys folder \nand trying to decrypt",'red')
msg1 = rsautil1.decrypt(message=res)
msg1 = msg1.decode('utf-8')
cprint(f"Decoded text: \n {msg1}",'green')
clean_tmp()
createTmp()
frames = countFrames()
decodeVideo(frames)
arrangeAndDecrypt()
# pip3 install gTTS pyttsx3