Added uv and validation for args.
This commit is contained in:
76
main.py
76
main.py
@@ -1,31 +1,73 @@
|
||||
import random
|
||||
import sys
|
||||
import time
|
||||
|
||||
alphaBase = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,. !="
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 6:
|
||||
print("Usage: python script.py <arg1> <arg2>")
|
||||
### Argument validation ###
|
||||
if len(sys.argv) < 7:
|
||||
print("Usage: uv run main.py [0-58] [0-58] [0-58] '[message]' 'e|d' [int]")
|
||||
sys.exit(1)
|
||||
|
||||
base_max = len(alphaBase)
|
||||
|
||||
if not is_number(sys.argv[1]) or not is_number(sys.argv[2]) or not is_number(sys.argv[3]):
|
||||
print("Invalid seed value.")
|
||||
sys.exit(1)
|
||||
|
||||
if not is_number(sys.argv[6]):
|
||||
print("Invalid iterations value.")
|
||||
sys.exit(1)
|
||||
|
||||
if int(sys.argv[1]) == 0 or int(sys.argv[1]) > base_max:
|
||||
seed1 = random.randint(1, base_max)
|
||||
else:
|
||||
seed1 = int(sys.argv[1])
|
||||
|
||||
if int(sys.argv[2]) == 0 or int(sys.argv[2]) > base_max:
|
||||
seed2 = random.randint(1, base_max)
|
||||
else:
|
||||
seed2 = int(sys.argv[2])
|
||||
|
||||
if int(sys.argv[3]) == 0 or int(sys.argv[3]) > base_max:
|
||||
seed3 = random.randint(1, base_max)
|
||||
else:
|
||||
seed3 = int(sys.argv[3])
|
||||
|
||||
if int(sys.argv[6]) < 0:
|
||||
iterations = 3
|
||||
else:
|
||||
iterations = int(sys.argv[6])
|
||||
|
||||
### Processing ###
|
||||
if sys.argv[5] == "e":
|
||||
for iteration in range(0, iterations):
|
||||
print("Iteration (not yet in use): ", iteration)
|
||||
|
||||
|
||||
# first iteration
|
||||
firstIterationResult = encode(int(sys.argv[1]), sys.argv[4])
|
||||
firstIterationResult = encode(seed1, sys.argv[4])
|
||||
print(firstIterationResult)
|
||||
|
||||
secondIterationResult = encode(int(sys.argv[2]), sys.argv[4])
|
||||
secondIterationResult = encode(seed2, sys.argv[4])
|
||||
print(secondIterationResult)
|
||||
|
||||
thirdIterationResult = encode(int(sys.argv[3]), sys.argv[4])
|
||||
thirdIterationResult = encode(seed3, sys.argv[4])
|
||||
# print(thirdIterationResult)
|
||||
print("Seeds: ", seed1, seed2, seed3, thirdIterationResult)
|
||||
elif sys.argv[5] == "d":
|
||||
firstIterationResult = decode(seed1, sys.argv[4])
|
||||
print(firstIterationResult)
|
||||
|
||||
secondIterationResult = decode(seed2, sys.argv[4])
|
||||
print(secondIterationResult)
|
||||
|
||||
thirdIterationResult = decode(seed3, sys.argv[4])
|
||||
print(thirdIterationResult)
|
||||
else:
|
||||
firstIterationResult = decode(int(sys.argv[1]), sys.argv[4])
|
||||
print(firstIterationResult)
|
||||
|
||||
secondIterationResult = decode(int(sys.argv[2]), sys.argv[4])
|
||||
print(secondIterationResult)
|
||||
|
||||
thirdIterationResult = decode(int(sys.argv[3]), sys.argv[4])
|
||||
print(thirdIterationResult)
|
||||
print("Invalid option!")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def encode(offset, message):
|
||||
@@ -64,5 +106,13 @@ def decode(offset, message):
|
||||
return resultMessage
|
||||
|
||||
|
||||
def is_number(i):
|
||||
try:
|
||||
int(i)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user