mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-05-13 01:18:31 +02:00
Added a2bits_list(chars) function which convert a string to its bits representation as a list of 0's and 1's.
This commit is contained in:
parent
1c593b70c7
commit
d0c1c62564
5 changed files with 27 additions and 2 deletions
2
LSB.py
Normal file → Executable file
2
LSB.py
Normal file → Executable file
|
@ -28,7 +28,7 @@ def hide(img, message):
|
||||||
|
|
||||||
(r, g, b) = img.getpixel((col, row))
|
(r, g, b) = img.getpixel((col, row))
|
||||||
|
|
||||||
# Convert in to bits
|
# Convert int to bits
|
||||||
r_bits = tools.bs(r)
|
r_bits = tools.bs(r)
|
||||||
g_bits = tools.bs(g)
|
g_bits = tools.bs(g)
|
||||||
b_bits = tools.bs(b)
|
b_bits = tools.bs(b)
|
||||||
|
|
0
__init__.py
Normal file → Executable file
0
__init__.py
Normal file → Executable file
0
basic.py
Normal file → Executable file
0
basic.py
Normal file → Executable file
0
pictures/Lenna.png
Normal file → Executable file
0
pictures/Lenna.png
Normal file → Executable file
Before Width: | Height: | Size: 464 KiB After Width: | Height: | Size: 464 KiB |
27
tools.py
Normal file → Executable file
27
tools.py
Normal file → Executable file
|
@ -7,11 +7,36 @@
|
||||||
def a2bits(chars):
|
def a2bits(chars):
|
||||||
"""
|
"""
|
||||||
Convert a string to its bits representation as a string of 0's and 1's.
|
Convert a string to its bits representation as a string of 0's and 1's.
|
||||||
|
|
||||||
|
>>> a2bits("Hello World!")
|
||||||
|
'010010000110010101101100011011000110111100100000010101110110111101110010011011000110010000100001'
|
||||||
"""
|
"""
|
||||||
return bin(reduce(lambda x, y : (x<<8)+y, (ord(c) for c in chars), 1))[3:]
|
return bin(reduce(lambda x, y : (x<<8)+y, (ord(c) for c in chars), 1))[3:]
|
||||||
|
|
||||||
|
def a2bits_list(chars):
|
||||||
|
"""
|
||||||
|
Convert a string to its bits representation as a list of 0's and 1's.
|
||||||
|
|
||||||
|
>>> a2bits_list("Hello Word!")
|
||||||
|
['01001000',
|
||||||
|
'01100101',
|
||||||
|
'01101100',
|
||||||
|
'01101100',
|
||||||
|
'01101111',
|
||||||
|
'00100000',
|
||||||
|
'01010111',
|
||||||
|
'01101111',
|
||||||
|
'01110010',
|
||||||
|
'01101100',
|
||||||
|
'01100100',
|
||||||
|
'00100001']
|
||||||
|
>>> "".join(a2bits_list("Hello World!"))
|
||||||
|
'010010000110010101101100011011000110111100100000010101110110111101110010011011000110010000100001'
|
||||||
|
"""
|
||||||
|
return [bin(ord(x))[2:].rjust(8,"0") for x in chars]
|
||||||
|
|
||||||
def bs(s):
|
def bs(s):
|
||||||
"""
|
"""
|
||||||
Convert a int to its bits representation as a string of 0's and 1's.
|
Convert an int to its bits representation as a string of 0's and 1's.
|
||||||
"""
|
"""
|
||||||
return str(s) if s<=1 else bs(s>>1) + str(s&1)
|
return str(s) if s<=1 else bs(s>>1) + str(s&1)
|
Loading…
Add table
Reference in a new issue