Replaced encode and decode with excode.
Replaced encode and decode with a single function, excode, that accepts a parameter for encode/decode and handles both actions.
This commit is contained in:
1
.python-version
Normal file
1
.python-version
Normal file
@@ -0,0 +1 @@
|
|||||||
|
3.13
|
||||||
32
main.py
32
main.py
@@ -47,13 +47,13 @@ def main():
|
|||||||
if sys.argv[2] == "e":
|
if sys.argv[2] == "e":
|
||||||
print("Encoding!")
|
print("Encoding!")
|
||||||
for iteration in range(0, iterations):
|
for iteration in range(0, iterations):
|
||||||
iteration_result = encode(seed_values[iteration], sys.argv[1])
|
iteration_result = excode(True, seed_values[iteration], sys.argv[1])
|
||||||
|
|
||||||
print("Result:", "\"" + iteration_result + "\"")
|
print("Result:", "\"" + iteration_result + "\"")
|
||||||
elif sys.argv[2] == "d":
|
elif sys.argv[2] == "d":
|
||||||
print("Decoding!")
|
print("Decoding!")
|
||||||
for iteration in range(0, iterations):
|
for iteration in range(0, iterations):
|
||||||
iteration_result = decode(seed_values[iteration], sys.argv[1])
|
iteration_result = excode(False, seed_values[iteration], sys.argv[1])
|
||||||
|
|
||||||
print("Result:", "\"" + iteration_result + "\"")
|
print("Result:", "\"" + iteration_result + "\"")
|
||||||
else:
|
else:
|
||||||
@@ -61,30 +61,20 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def encode(offset: int, message: str) -> str:
|
def excode(encoding: bool, offset: int, message: str) -> str:
|
||||||
result_message: str = ""
|
result_message: str = ""
|
||||||
|
|
||||||
for index_a in range(len(message)):
|
for index_a in range(len(message)):
|
||||||
for index_b in range(len(alpha_base)):
|
for index_b in range(len(alpha_base)):
|
||||||
if message[index_a] == alpha_base[index_b]:
|
if message[index_a] == alpha_base[index_b]:
|
||||||
location = index_b + offset
|
if encoding:
|
||||||
if location > (len(alpha_base) - 1):
|
location = index_b + offset
|
||||||
location = location - (len(alpha_base) - 1)
|
if location > (len(alpha_base) - 1):
|
||||||
result_message = result_message + alpha_base[location]
|
location = location - (len(alpha_base) - 1)
|
||||||
break
|
else:
|
||||||
|
location = index_b - offset
|
||||||
return result_message
|
if location < 0:
|
||||||
|
location = location + (len(alpha_base) - 1)
|
||||||
|
|
||||||
def decode(offset: int, message: str) -> str:
|
|
||||||
result_message: str = ""
|
|
||||||
|
|
||||||
for index_a in range(len(message)):
|
|
||||||
for index_b in range(len(alpha_base)):
|
|
||||||
if message[index_a] == alpha_base[index_b]:
|
|
||||||
location = index_b - offset
|
|
||||||
if location < 0:
|
|
||||||
location = location + (len(alpha_base) - 1)
|
|
||||||
result_message = result_message + alpha_base[location]
|
result_message = result_message + alpha_base[location]
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
7
pyproject.toml
Normal file
7
pyproject.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[project]
|
||||||
|
name = "enigmamachine"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.13"
|
||||||
|
dependencies = []
|
||||||
Reference in New Issue
Block a user