-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstega_lsb.py
30 lines (26 loc) · 942 Bytes
/
stega_lsb.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
import binascii
import sys
def byteFromBitstring(bitstring):
return int(bitstring, 2)
def bitstringFromByte(byte):
return ''.join([str((byte >> i) & 0x01) for i in range(7, -1, -1)])
def reveal(image, offset, localoffset):
message = ''
bitstring = ''
pixel = offset
while pixel < len(image):
bit = bitstringFromByte(int(binascii.hexlify(image[pixel]),16))[-1]
bitstring += bit
if len(bitstring) > 7:
message += chr(byteFromBitstring(bitstring))
bitstring = ''
pixel += localoffset
return message
if __name__ == '__main__':
if len(sys.argv) < 4:
print "Dad LSB Tool"
print "Usage: %s <file> <offset> <local offset>" % sys.argv[0]
print "- offset : from start of <file>"
print "- local offset: between each LSB"
else:
print reveal(open(sys.argv[1], 'rb').read(), int(sys.argv[2], 16), int(sys.argv[3]))