Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Steganorgraphy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PRASHANT SAROJ
Steganorgraphy
Commits
a416c531
Commit
a416c531
authored
Sep 22, 2018
by
Prashant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding encode.py. This file is used for encoding messages
parent
d9303c47
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
encode.py
encode.py
+64
-0
No files found.
encode.py
0 → 100644
View file @
a416c531
import
math
from
PIL
import
Image
def
encodeLzw
(
uncompressed
):
dict_size
=
256
dictionary
=
{}
for
i
in
range
(
dict_size
):
dictionary
[
chr
(
i
)]
=
i
w
=
""
for
c
in
uncompressed
:
wc
=
w
+
c
if
wc
in
dictionary
:
w
=
wc
else
:
encoded_version
.
append
(
dictionary
[
w
])
dictionary
[
wc
]
=
dict_size
dict_size
+=
1
w
=
c
if
w
:
encoded_version
.
append
(
dictionary
[
w
])
# appending length of list as first element
N
=
len
(
encoded_version
)
encoded_version
.
append
(
N
)
encoded_version
[
0
],
encoded_version
[
N
]
=
encoded_version
[
N
],
encoded_version
[
0
]
encoded_version
=
[]
# int length is taken to be 16 bits
if
__name__
==
"__main__"
:
input_string
=
input
(
"Enter a string to encode: "
)
encodeLzw
(
input_string
)
encoded_bin_version
=
[]
# final list to insert in image each entry is 16-bit string
for
i
in
range
(
0
,
len
(
encoded_version
)):
current_string
=
'{0:016b}'
.
format
(
encoded_version
[
i
])
for
j
in
range
(
0
,
8
):
# parsing current string into 8 parts
encoded_bin_version
.
append
(
current_string
[
2
*
j
:
2
*
j
+
2
])
ctr
=
0
n
=
len
(
encoded_bin_version
)
-
1
im
=
Image
.
open
(
'input.png'
)
pixelMap
=
im
.
load
()
img
=
Image
.
new
(
im
.
mode
,
im
.
size
)
pixelsNew
=
img
.
load
()
for
i
in
range
(
0
,
img
.
size
[
0
]):
for
j
in
range
(
0
,
img
.
size
[
1
]):
if
ctr
>
n
:
pixelsNew
[
i
,
j
]
=
pixelMap
[
i
,
j
]
else
:
original_pixel
=
pixelMap
[
i
,
j
][
0
]
# changing the value of red pixel
encoded_pixel
=
4
*
math
.
floor
(
original_pixel
/
4
)
+
int
(
encoded_bin_version
[
ctr
],
2
)
pixelsNew
[
i
,
j
]
=
(
encoded_pixel
,
pixelMap
[
i
,
j
][
1
],
pixelMap
[
i
,
j
][
2
])
ctr
=
ctr
+
1
img
.
save
(
'output.png'
)
img
.
close
()
im
.
close
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment