save point
-Added parser for input and arguments
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
# Miguel Muniz
|
||||
# CS454
|
||||
|
||||
import argparse
|
||||
|
||||
def DES_Encrypt(data_block, key, operation):
|
||||
|
||||
# # Initialize the key schedule
|
||||
# key_schedule = [0] * 56
|
||||
# for i in range(64):
|
||||
# key_schedule[i] = key[i % len(key)]
|
||||
|
||||
# Initialize the initial permutation
|
||||
initial_permutation = [0] * 56
|
||||
for i in range(56):
|
||||
initial_permutation[i] = i
|
||||
print (initial_permutation)
|
||||
|
||||
|
||||
|
||||
def parse_variables(file_path):
|
||||
variables = {}
|
||||
try:
|
||||
with open(file_path, 'r') as file:
|
||||
for line in file:
|
||||
# Remove any extra spaces and ignore empty lines
|
||||
line = line.strip()
|
||||
if ':' in line and line:
|
||||
key, value = line.split(':', 1)
|
||||
variables[key.strip()] = value.strip()
|
||||
except FileNotFoundError:
|
||||
print(f"Error: The file {file_path} was not found.")
|
||||
return variables
|
||||
|
||||
def main():
|
||||
# Set up command-line argument parsing
|
||||
parser = argparse.ArgumentParser(description='Parse variables for encryption or decryption.')
|
||||
parser.add_argument('file', type=str, help='Path to the text file containing the variables.')
|
||||
|
||||
# Parse the arguments
|
||||
args = parser.parse_args()
|
||||
|
||||
# Parse the file and retrieve variables
|
||||
variables = parse_variables(args.file)
|
||||
|
||||
# Get data_block and key from the parsed variables
|
||||
data_block = variables.get('data_block', '')
|
||||
key = variables.get('key', '')
|
||||
operation = variables.get('operation','')
|
||||
|
||||
# Print the variables
|
||||
print(f"Data Block: {data_block}")
|
||||
print(f"Key: {key}")
|
||||
print(f"Operation: {operation}")
|
||||
|
||||
DES_Encrypt(data_block, key, operation)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user