mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-05-13 01:18:31 +02:00
Removed reveal_slow(). Factorization of code (table of color components [r,g,b]).
This commit is contained in:
parent
707e69a274
commit
e756196ee3
1 changed files with 12 additions and 57 deletions
51
lsb-s.py
51
lsb-s.py
|
@ -78,9 +78,10 @@ def reveal(img):
|
||||||
limit = None
|
limit = None
|
||||||
for row in xrange(height):
|
for row in xrange(height):
|
||||||
for col in xrange(width):
|
for col in xrange(width):
|
||||||
r, g, b = img.getpixel((col, row))
|
|
||||||
|
|
||||||
buff += (r&1)<<(7-count)
|
# color = [r, g, b]
|
||||||
|
for color in img.getpixel((col, row)):
|
||||||
|
buff += (color&1)<<(7-count)
|
||||||
count += 1
|
count += 1
|
||||||
if count == 8:
|
if count == 8:
|
||||||
bitab.append(chr(buff))
|
bitab.append(chr(buff))
|
||||||
|
@ -91,56 +92,10 @@ def reveal(img):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
buff += (g&1)<<(7-count)
|
|
||||||
count += 1
|
|
||||||
if count == 8:
|
|
||||||
bitab.append(chr(buff))
|
|
||||||
buff, count = 0, 0
|
|
||||||
if bitab[-1] == ":" and limit == None:
|
|
||||||
try:
|
|
||||||
limit = int("".join(bitab[:-1]))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
buff += (b&1)<<(7-count)
|
|
||||||
count += 1
|
|
||||||
if count == 8:
|
|
||||||
bitab.append(chr(buff))
|
|
||||||
buff, count = 0, 0
|
|
||||||
if bitab[-1] == ":" and limit == None:
|
|
||||||
try:
|
|
||||||
limit = int("".join(bitab[:-1]))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if len(bitab)-len(str(limit))-1 == limit :
|
if len(bitab)-len(str(limit))-1 == limit :
|
||||||
return "".join(bitab)[len(str(limit))+1:]
|
return "".join(bitab)[len(str(limit))+1:]
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def reveal_slow(img):
|
|
||||||
"""
|
|
||||||
Find a message in an image
|
|
||||||
(with the LSB technique).
|
|
||||||
"""
|
|
||||||
width, height = img.size
|
|
||||||
bits = []
|
|
||||||
for row in xrange(height):
|
|
||||||
for col in xrange(width):
|
|
||||||
r, g, b = img.getpixel((col, row))
|
|
||||||
|
|
||||||
bits.append([tools.bs(r)[-1], tools.bs(g)[-1], tools.bs(b)[-1]])
|
|
||||||
|
|
||||||
if int("".join(bits[-8:]), 2) == 126:
|
|
||||||
# chr(126) = '~ '
|
|
||||||
list_of_string_bits = ["".join(bits[i:(i+8)]) for i in range(0, len(bits)-8, 8)]
|
|
||||||
|
|
||||||
list_of_character = [chr(int(elem, 2)) for elem in list_of_string_bits]
|
|
||||||
return "".join(list_of_character)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Point of entry in execution mode.
|
# Point of entry in execution mode.
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
Loading…
Add table
Reference in a new issue