mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-05-12 17:18:30 +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
69
lsb-s.py
69
lsb-s.py
|
@ -78,69 +78,24 @@ def reveal(img):
|
|||
limit = None
|
||||
for row in xrange(height):
|
||||
for col in xrange(width):
|
||||
r, g, b = img.getpixel((col, row))
|
||||
|
||||
buff += (r&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 += (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
|
||||
|
||||
# color = [r, g, b]
|
||||
for color in img.getpixel((col, row)):
|
||||
buff += (color&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 :
|
||||
return "".join(bitab)[len(str(limit))+1:]
|
||||
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__':
|
||||
# Point of entry in execution mode.
|
||||
from optparse import OptionParser
|
||||
|
|
Loading…
Add table
Reference in a new issue