-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode.py
More file actions
76 lines (63 loc) · 1.85 KB
/
decode.py
File metadata and controls
76 lines (63 loc) · 1.85 KB
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
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 17 21:46:35 2018
@author: Grzesiek-UC
"""
#!/usr/bin/python
import sys, getopt
from PIL import Image
import numpy as np
from math import floor
def setBit(var, offset):
mask = 1 << offset
return(var | mask)
def clearBit(var, offset):
mask = ~(1 << offset)
return(var & mask)
def testBit(var, offset):
mask = 1 << offset
return(var & mask)
def decryptFlat(channel):
bits = 0
chars = 0
output = ""
byteList = []
for idx, byte in enumerate(channel):
chars += testBit(channel[idx], 0)<<bits
bits = (bits + 1) % 8
if bits == 0:
output += chr(chars)
byteList.append(chars)
chars = 0
if output.find("</data>") != -1:
return output[6:output.index('</data>')], byteList[6:output.index('</data>')]
return "error - no data"
def main(argv):
picfile = ''
textfile = ''
try:
opts, args = getopt.getopt(argv,"hp:t:",["pfile=","tfile="])
except getopt.GetoptError:
print('decode.py -p <picture> -t <text>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print( 'decode.py -p <picture> -t <text>')
sys.exit()
elif opt in ("-p", "--pfile"):
picfile = arg
elif opt in ("-t", "--tfile"):
textfile = arg
imgIn = Image.open(picfile)
imgArray = np.array(imgIn)
imgArray = imgArray.reshape(-1)
output, byteList = decryptFlat(imgArray)
byteList = bytearray(byteList)
print('hidden message: ', byteList.decode('cp1250'))
file = open(textfile, 'wb')
for byte in byteList:
file.write(byte.to_bytes(1, byteorder='big'))
file.close()
print('Decription process succesfull')
if __name__ == "__main__":
main(sys.argv[1:])