Skip to content

Commit b74be1c

Browse files
committed
Hell of an improvement
1 parent d007c68 commit b74be1c

13 files changed

+646
-297
lines changed

.gitignore

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# UV
98+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
#uv.lock
102+
103+
# poetry
104+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105+
# This is especially recommended for binary packages to ensure reproducibility, and is more
106+
# commonly ignored for libraries.
107+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108+
#poetry.lock
109+
110+
# pdm
111+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112+
#pdm.lock
113+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114+
# in version control.
115+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116+
.pdm.toml
117+
.pdm-python
118+
.pdm-build/
119+
120+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121+
__pypackages__/
122+
123+
# Celery stuff
124+
celerybeat-schedule
125+
celerybeat.pid
126+
127+
# SageMath parsed files
128+
*.sage.py
129+
130+
# Environments
131+
.env
132+
.venv
133+
env/
134+
venv/
135+
ENV/
136+
env.bak/
137+
venv.bak/
138+
139+
# Spyder project settings
140+
.spyderproject
141+
.spyproject
142+
143+
# Rope project settings
144+
.ropeproject
145+
146+
# mkdocs documentation
147+
/site
148+
149+
# mypy
150+
.mypy_cache/
151+
.dmypy.json
152+
dmypy.json
153+
154+
# Pyre type checker
155+
.pyre/
156+
157+
# pytype static type analyzer
158+
.pytype/
159+
160+
# Cython debug symbols
161+
cython_debug/
162+
163+
# PyCharm
164+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166+
# and can be added to the global gitignore or merged into this file. For a more nuclear
167+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
168+
#.idea/

LICENSE.txt

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) 2024 Nils Moreau--Thomas
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1. To build the package
2+
```
3+
python ./setup.py bdist_wheel
4+
```
5+
2. To install the package
6+
```
7+
pip install .
8+
```

periodic_encryption/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# __init__.py
2+
__version__ = "0.0.1"
3+
__author__ = "NilsMT"
4+
__email__ = "[email protected]"
5+
6+
from periodic_encryption.encryption import *
7+
from periodic_encryption.vigenerecipher import *
8+
from periodic_encryption.element import *

periodic_encryption/element.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import periodictable as pt
2+
3+
##############################################
4+
# CUSTOM ELEMENT TO HANDLE CODES OUT OF RANGE
5+
##############################################
6+
7+
class LoopCounterElement(pt.core.Element):
8+
"""
9+
A custom element class to handle elements with codes out of the periodic table range.\n
10+
It store in the mass: `900 + loop counter` how many time we looped out of range over the periodic table to finaly fit the ASCII code in the table.\n
11+
The name store the element that we finally are able to fit into as last part this element name.\n
12+
"""
13+
def __init__(self, cnt: int, el: pt.core.Element):
14+
# Initialize the parent class
15+
super().__init__(
16+
name=f"Loopcounterium-{cnt}-{el.name}",
17+
symbol=f"Lc{el.symbol}{cnt}",
18+
Z=900 + cnt,
19+
ions=(),
20+
table="public"
21+
)
22+
23+
self._mass = 900 + cnt
24+
25+
@property
26+
def mass(self):
27+
return self._mass
28+
29+
@mass.setter
30+
def mass(self, value):
31+
self._mass = value
32+
33+
##############################################
34+
# GET ELEMENTS
35+
##############################################
36+
37+
def getElementByNumber(number: int) -> pt.core.Element:
38+
return pt.elements[number]
39+
40+
41+
42+
def getElementByName(name: str) -> pt.core.Element:
43+
return pt.elements.name(name)
44+
45+
46+
47+
def getLastElement() -> pt.core.Element:
48+
bst = 0
49+
for e in pt.elements:
50+
if e.number > bst:
51+
bst = e.number
52+
return getElementByNumber(bst)
53+
54+
55+
56+
def getElementBySymbol(symbol: str) -> pt.core.Element:
57+
return pt.elements.symbol(symbol)
58+
59+
##############################################
60+
# TEXT ----> ELEMENTS
61+
##############################################
62+
63+
def turnCharacterIntoElement(character: chr) -> pt.core.Element:
64+
el = None
65+
last = getLastElement().number
66+
67+
code = ord(character)
68+
69+
#gotta truncate or it won't fit periodic table
70+
if code > last:
71+
quot = code // last
72+
truncated_code = code % last
73+
74+
return LoopCounterElement(
75+
quot,
76+
getElementByNumber(truncated_code)
77+
)
78+
79+
else:
80+
return getElementByNumber(code)
81+
82+
83+
84+
def turnStringIntoElements(string: str) -> list[pt.core.Element]:
85+
lst: list[pt.core.Element] = []
86+
for c in string:
87+
lst.append(turnCharacterIntoElement(c))
88+
return lst
89+
90+
##############################################
91+
# ELEMENTS ----> TEXT
92+
##############################################
93+
94+
def turnElementIntoCharacter(element: pt.core.Element) -> chr:
95+
if (element.number < 900):
96+
#its a normal element
97+
return chr(element.number)
98+
else:
99+
#its a loop counter element
100+
loopCount = element.number - 900
101+
normalElementName = element.name.split("-")[-1]
102+
103+
excess = loopCount * getLastElement().number
104+
105+
return chr(excess + getElementByName(normalElementName).number)
106+
107+
108+
109+
def turnElementsIntoString(elementList: list[pt.core.Element]) -> str:
110+
string = ""
111+
for e in elementList:
112+
string += turnElementIntoCharacter(e)
113+
return string

0 commit comments

Comments
 (0)