Skip to content

Commit a65539c

Browse files
committed
Initial commit
1 parent afcd02c commit a65539c

28 files changed

+1492
-0
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Type '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
- OS: [e.g. Windows 10]
28+
- Python/Tk Version
29+
30+
**Additional context**
31+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.gitignore

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
.hypothesis/
51+
.pytest_cache/
52+
53+
# Translations
54+
*.mo
55+
*.pot
56+
57+
# Django stuff:
58+
*.log
59+
local_settings.py
60+
db.sqlite3
61+
62+
# Flask stuff:
63+
instance/
64+
.webassets-cache
65+
66+
# Scrapy stuff:
67+
.scrapy
68+
69+
# Sphinx documentation
70+
docs/_build/
71+
72+
# PyBuilder
73+
target/
74+
75+
# Jupyter Notebook
76+
.ipynb_checkpoints
77+
78+
# IPython
79+
profile_default/
80+
ipython_config.py
81+
82+
# pyenv
83+
.python-version
84+
85+
# pipenv
86+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
87+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
88+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
89+
# install all needed dependencies.
90+
#Pipfile.lock
91+
92+
# celery beat schedule file
93+
celerybeat-schedule
94+
95+
# SageMath parsed files
96+
*.sage.py
97+
98+
# Environments
99+
.env
100+
.venv
101+
env/
102+
venv/
103+
ENV/
104+
env.bak/
105+
venv.bak/
106+
107+
# Spyder project settings
108+
.spyderproject
109+
.spyproject
110+
111+
# Rope project settings
112+
.ropeproject
113+
114+
# mkdocs documentation
115+
/site
116+
117+
# mypy
118+
.mypy_cache/
119+
.dmypy.json
120+
dmypy.json
121+
122+
# Pyre type checker
123+
.pyre/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 5x
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# cryptography-gui-app
2+
3+
An application for encrypting/decrypting text with few symmetric/asymmetric crypto algorithms.
4+
5+
Features:
6+
- Multi alphabet crypt support (English, Ukraine, Russian);
7+
- Symmetric/Asymmetric mode;
8+
- Decrypt brute force iterator;
9+
- Native Tk GUI.
10+
11+
Ciphers:
12+
- Caesar cipher;
13+
- Trithemius cipher (Linear equation/Not linear equation/ slogan);
14+
- Gamma cipher (PRNG based);
15+
- DES (mode CFB);
16+
- Asymmetric cipher (public/private key realization).
17+
18+
## Build Windows Application
19+
20+
To create runnable execute application use next:
21+
```bash
22+
pyinstaller --onefile --windowed --name cryptography-gui-app app.py
23+
```
24+
[More info about PyInstaller](https://www.pyinstaller.org/)
25+
26+
## Requirements
27+
28+
* Python 3.4 or later
29+
* pycryptodome
30+
* pyinstaller
31+
32+
## Application screenshots
33+
![Application screenshot](assets/screenshots.png)
34+
35+
## Support & Contributing
36+
Anyone is welcome to contribute. If you decide to get involved, please take a moment and check out the following:
37+
38+
* [Bug reports](.github/ISSUE_TEMPLATE/bug_report.md)
39+
* [Feature requests](.github/ISSUE_TEMPLATE/feature_request.md)
40+
41+
## License
42+
43+
The code is available under the [MIT license](LICENSE).

__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/python3,4
2+
# -*- coding: utf-8 -*-
3+
"""cryptography-gui-app"""

app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from gui import MainWindow
2+
3+
if __name__ == "__main__":
4+
main = MainWindow()
5+
main.mainloop()

assets/screenshots.png

38.6 KB
Loading

crypt/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from .caesar_cipher import CaesarCipher
2+
from .decrypt_iter import DecryptIter
3+
from .trithemius_cipher import TrithemiusCipher, TrithemiusLinearEquation,\
4+
TrithemiusAssocReplace, LinearEquationException
5+
from .gamma_cipher import GammaCipher
6+
from .des_cipher import DESCipher
7+
from .asymmetric import AsymmetricCipher
8+
9+
10+
__all__ = [
11+
"CaesarCipher",
12+
"DecryptIter",
13+
"TrithemiusCipher",
14+
"TrithemiusLinearEquation",
15+
"TrithemiusAssocReplace",
16+
"LinearEquationException",
17+
"GammaCipher",
18+
"DESCipher",
19+
"AsymmetricCipher",
20+
]

crypt/alphabet.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from string import ascii_lowercase, ascii_uppercase, digits, punctuation
2+
3+
whitespace = " \t"
4+
EN = (ascii_lowercase, ascii_uppercase, digits, punctuation, whitespace)
5+
RU = ("АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ", "абвгдеёжзийклмнопрстуфхцчшщъыьэюя", digits, punctuation, whitespace)
6+
UA = ("АБВГҐДЕЄЖЗИІЇЙКЛМНОПРСТУФХЦЧШЩЬЭЮЯ", "абвгґдеєжзиіїйклмнопрстуфхцчшщьэюя", digits, punctuation, whitespace)
7+
8+
9+
def get_alphabet(lang=None):
10+
alphabets = {
11+
"EN": EN,
12+
"RU": RU,
13+
"UA": UA
14+
}
15+
16+
return alphabets.get(lang, EN)

crypt/asymmetric.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from crypt.utils.number_theory_algs import extended_gcd
2+
from crypt.utils.bitstr import str_to_bits, bits_to_str, positive_align_str
3+
from crypt.utils.knapsack import knapsack
4+
5+
6+
class AsymmetricCipher(object):
7+
def encrypt(self, plain_text, public_seq):
8+
block_size = len(public_seq)
9+
text = str_to_bits(plain_text)
10+
text = positive_align_str(text, block_size)
11+
12+
blocks = tuple(zip(*[iter(text)] * block_size))
13+
14+
crt_values = []
15+
for index, block in enumerate(blocks):
16+
total_weight = self._block_total_weight(block, public_seq)
17+
crt_values.append(total_weight)
18+
19+
return crt_values
20+
21+
def decrypt(self, cipher_text, private_seq, m, t):
22+
_, _, neg_t = extended_gcd(m, t)
23+
24+
plain_bits = []
25+
for num in cipher_text:
26+
value = (neg_t * num) % m
27+
bits_block = knapsack(private_seq, value)
28+
plain_bits.append(bits_block)
29+
30+
plain_text = bits_to_str(plain_bits)
31+
32+
return plain_text
33+
34+
@staticmethod
35+
def gen_public_key(secret_sec, t, m):
36+
return [(t * i) % m for i in secret_sec]
37+
38+
def _block_total_weight(self, bits, weight_values):
39+
return sum(w for w, bit in zip(weight_values, bits) if bit == "1")
40+
41+
42+
if __name__ == "__main__":
43+
test_data = """The quick brown fox jumps over the lazy dog."""
44+
secret_key = [1, 3, 5, 11, 21, 44, 87, 175, 349, 701]
45+
s = 1590
46+
m = 43
47+
48+
cipher = AsymmetricCipher()
49+
50+
# eq [43, 129, 215, 473, 903, 302, 561, 1165, 697, 1523]
51+
public_key = AsymmetricCipher.gen_public_key(secret_key, m, s)
52+
crt_text = cipher.encrypt(test_data, public_key)
53+
plain_text = cipher.decrypt(crt_text, secret_key, s, m)
54+
55+
print(public_key)
56+
print(crt_text)
57+
print(plain_text)

crypt/caesar_cipher.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from crypt.alphabet import get_alphabet
2+
from crypt.cipher_abc import CipherABC
3+
4+
5+
class CaesarCipher(CipherABC):
6+
def __init__(self, key, alphabet='EN'):
7+
super().__init__(key)
8+
self.symbols_collection = get_alphabet(alphabet)
9+
10+
@CipherABC.key.setter
11+
def key(self, value):
12+
self._key = int(value)
13+
14+
def encrypt(self, plain_text):
15+
return self._shift_msg(self._key, plain_text)
16+
17+
def decrypt(self, cipher_text):
18+
return self._shift_msg(-self._key, cipher_text)
19+
20+
def _shift_msg(self, key, message):
21+
shift_map = self._shift_map(key)
22+
shifted_msg = (shift_map.get(char, char) for char in message)
23+
24+
return "".join(shifted_msg)
25+
26+
def _shift_map(self, shift):
27+
assoc_map = {}
28+
29+
for symbols in self.symbols_collection:
30+
symbols_len = len(symbols)
31+
32+
if symbols_len == 0:
33+
continue
34+
35+
for j in range(symbols_len):
36+
in_char = symbols[j]
37+
shifted = (j + shift) % symbols_len
38+
assoc_map[in_char] = symbols[shifted]
39+
40+
return assoc_map
41+
42+
43+
if __name__ == "__main__":
44+
cipher = CaesarCipher("4")
45+
crt_text = cipher.encrypt("the quick brown fox jumps over the lazy dog.")
46+
plain_text = cipher.decrypt(crt_text)
47+
48+
print(crt_text)
49+
print(plain_text)

0 commit comments

Comments
 (0)