Skip to content

Commit 5a0e358

Browse files
committed
Supplement materials for the bitwise operators article
1 parent c18a5b4 commit 5a0e358

File tree

9 files changed

+607
-0
lines changed

9 files changed

+607
-0
lines changed

bitwise-operators/.gitignore

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/python,pycharm,visualstudiocode,sublimetext
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=python,pycharm,visualstudiocode,sublimetext
3+
4+
### PyCharm ###
5+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
6+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7+
8+
# User-specific stuff
9+
.idea/
10+
.idea/**/workspace.xml
11+
.idea/**/tasks.xml
12+
.idea/**/usage.statistics.xml
13+
.idea/**/dictionaries
14+
.idea/**/shelf
15+
16+
# Generated files
17+
.idea/**/contentModel.xml
18+
19+
# Sensitive or high-churn files
20+
.idea/**/dataSources/
21+
.idea/**/dataSources.ids
22+
.idea/**/dataSources.local.xml
23+
.idea/**/sqlDataSources.xml
24+
.idea/**/dynamic.xml
25+
.idea/**/uiDesigner.xml
26+
.idea/**/dbnavigator.xml
27+
28+
# Gradle
29+
.idea/**/gradle.xml
30+
.idea/**/libraries
31+
32+
# Gradle and Maven with auto-import
33+
# When using Gradle or Maven with auto-import, you should exclude module files,
34+
# since they will be recreated, and may cause churn. Uncomment if using
35+
# auto-import.
36+
# .idea/artifacts
37+
# .idea/compiler.xml
38+
# .idea/jarRepositories.xml
39+
# .idea/modules.xml
40+
# .idea/*.iml
41+
# .idea/modules
42+
# *.iml
43+
# *.ipr
44+
45+
# CMake
46+
cmake-build-*/
47+
48+
# Mongo Explorer plugin
49+
.idea/**/mongoSettings.xml
50+
51+
# File-based project format
52+
*.iws
53+
54+
# IntelliJ
55+
out/
56+
57+
# mpeltonen/sbt-idea plugin
58+
.idea_modules/
59+
60+
# JIRA plugin
61+
atlassian-ide-plugin.xml
62+
63+
# Cursive Clojure plugin
64+
.idea/replstate.xml
65+
66+
# Crashlytics plugin (for Android Studio and IntelliJ)
67+
com_crashlytics_export_strings.xml
68+
crashlytics.properties
69+
crashlytics-build.properties
70+
fabric.properties
71+
72+
# Editor-based Rest Client
73+
.idea/httpRequests
74+
75+
# Android studio 3.1+ serialized cache file
76+
.idea/caches/build_file_checksums.ser
77+
78+
### PyCharm Patch ###
79+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
80+
81+
# *.iml
82+
# modules.xml
83+
# .idea/misc.xml
84+
# *.ipr
85+
86+
# Sonarlint plugin
87+
# https://plugins.jetbrains.com/plugin/7973-sonarlint
88+
.idea/**/sonarlint/
89+
90+
# SonarQube Plugin
91+
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
92+
.idea/**/sonarIssues.xml
93+
94+
# Markdown Navigator plugin
95+
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
96+
.idea/**/markdown-navigator.xml
97+
.idea/**/markdown-navigator-enh.xml
98+
.idea/**/markdown-navigator/
99+
100+
# Cache file creation bug
101+
# See https://youtrack.jetbrains.com/issue/JBR-2257
102+
.idea/$CACHE_FILE$
103+
104+
# CodeStream plugin
105+
# https://plugins.jetbrains.com/plugin/12206-codestream
106+
.idea/codestream.xml
107+
108+
### Python ###
109+
# Byte-compiled / optimized / DLL files
110+
__pycache__/
111+
*.py[cod]
112+
*$py.class
113+
114+
# C extensions
115+
*.so
116+
117+
# Distribution / packaging
118+
.Python
119+
build/
120+
develop-eggs/
121+
dist/
122+
downloads/
123+
eggs/
124+
.eggs/
125+
lib/
126+
lib64/
127+
parts/
128+
sdist/
129+
var/
130+
wheels/
131+
pip-wheel-metadata/
132+
share/python-wheels/
133+
*.egg-info/
134+
.installed.cfg
135+
*.egg
136+
MANIFEST
137+
138+
# PyInstaller
139+
# Usually these files are written by a python script from a template
140+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
141+
*.manifest
142+
*.spec
143+
144+
# Installer logs
145+
pip-log.txt
146+
pip-delete-this-directory.txt
147+
148+
# Unit test / coverage reports
149+
htmlcov/
150+
.tox/
151+
.nox/
152+
.coverage
153+
.coverage.*
154+
.cache
155+
nosetests.xml
156+
coverage.xml
157+
*.cover
158+
*.py,cover
159+
.hypothesis/
160+
.pytest_cache/
161+
pytestdebug.log
162+
163+
# Translations
164+
*.mo
165+
*.pot
166+
167+
# Django stuff:
168+
*.log
169+
local_settings.py
170+
db.sqlite3
171+
db.sqlite3-journal
172+
173+
# Flask stuff:
174+
instance/
175+
.webassets-cache
176+
177+
# Scrapy stuff:
178+
.scrapy
179+
180+
# Sphinx documentation
181+
docs/_build/
182+
doc/_build/
183+
184+
# PyBuilder
185+
target/
186+
187+
# Jupyter Notebook
188+
.ipynb_checkpoints
189+
190+
# IPython
191+
profile_default/
192+
ipython_config.py
193+
194+
# pyenv
195+
.python-version
196+
197+
# pipenv
198+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
199+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
200+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
201+
# install all needed dependencies.
202+
#Pipfile.lock
203+
204+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
205+
__pypackages__/
206+
207+
# Celery stuff
208+
celerybeat-schedule
209+
celerybeat.pid
210+
211+
# SageMath parsed files
212+
*.sage.py
213+
214+
# Environments
215+
.env
216+
.venv
217+
env/
218+
venv/
219+
ENV/
220+
env.bak/
221+
venv.bak/
222+
223+
# Spyder project settings
224+
.spyderproject
225+
.spyproject
226+
227+
# Rope project settings
228+
.ropeproject
229+
230+
# mkdocs documentation
231+
/site
232+
233+
# mypy
234+
.mypy_cache/
235+
.dmypy.json
236+
dmypy.json
237+
238+
# Pyre type checker
239+
.pyre/
240+
241+
# pytype static type analyzer
242+
.pytype/
243+
244+
### SublimeText ###
245+
# Cache files for Sublime Text
246+
*.tmlanguage.cache
247+
*.tmPreferences.cache
248+
*.stTheme.cache
249+
250+
# Workspace files are user-specific
251+
*.sublime-workspace
252+
253+
# Project files should be checked into the repository, unless a significant
254+
# proportion of contributors will probably not be using Sublime Text
255+
# *.sublime-project
256+
257+
# SFTP configuration file
258+
sftp-config.json
259+
260+
# Package control specific files
261+
Package Control.last-run
262+
Package Control.ca-list
263+
Package Control.ca-bundle
264+
Package Control.system-ca-bundle
265+
Package Control.cache/
266+
Package Control.ca-certs/
267+
Package Control.merged-ca-bundle
268+
Package Control.user-ca-bundle
269+
oscrypto-ca-bundle.crt
270+
bh_unicode_properties.cache
271+
272+
# Sublime-github package stores a github token in this file
273+
# https://packagecontrol.io/packages/sublime-github
274+
GitHub.sublime-settings
275+
276+
### VisualStudioCode ###
277+
.vscode/*
278+
!.vscode/settings.json
279+
!.vscode/tasks.json
280+
!.vscode/launch.json
281+
!.vscode/extensions.json
282+
*.code-workspace
283+
284+
### VisualStudioCode Patch ###
285+
# Ignore all local history of files
286+
.history
287+
288+
# End of https://www.toptal.com/developers/gitignore/api/python,pycharm,visualstudiocode,sublimetext

bitwise-operators/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Bitwise Operators in Python
2+
3+
Source code of the least-significant bit **steganography** example from the [Bitwise Operators in Python](https://realpython.com/python-bitwise-operators/) article.
4+
5+
## Installation
6+
7+
There are no external dependencies except for a Python interpreter.
8+
9+
## Running
10+
11+
Change directory to the current folder, where this `README.md` file is located, and then execute Python module:
12+
13+
```shell
14+
$ python -m stegano /path/to/bitmap (--encode /path/to/file | --decode | --erase)
15+
```
16+
17+
For example, to extract a secret file from the attached bitmap, type the following:
18+
19+
```shell
20+
$ python -m stegano example.bmp -d
21+
Extracted a secret file: podcast.mp4
22+
```

bitwise-operators/example.bmp

4.06 MB
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Runnable module, can be executed as:
3+
$ python -m stegano
4+
"""
5+
6+
from .bitmap import Bitmap
7+
from .cli import CommandLineArguments, parse_args
8+
from .decoder import decode
9+
from .encoder import encode
10+
from .eraser import erase
11+
12+
13+
def main(args: CommandLineArguments) -> None:
14+
"""Entry point to the script."""
15+
with Bitmap(args.bitmap) as bitmap:
16+
if args.encode:
17+
encode(bitmap, args.encode)
18+
elif args.decode:
19+
decode(bitmap)
20+
elif args.erase:
21+
erase(bitmap)
22+
23+
24+
if __name__ == "__main__":
25+
try:
26+
main(parse_args())
27+
except Exception as ex: # pylint: disable=W0703
28+
print(ex)

0 commit comments

Comments
 (0)