Simplified if/else tree for translation
This commit is contained in:
parent
aa40d41c49
commit
836f09ab25
69
crypttool.py
69
crypttool.py
@ -23,6 +23,8 @@ def translate(inputString, inputType, outputType):
|
|||||||
result = ""
|
result = ""
|
||||||
if(inputType == outputType):
|
if(inputType == outputType):
|
||||||
result = inputString
|
result = inputString
|
||||||
|
return result
|
||||||
|
|
||||||
if (inputType == 5):
|
if (inputType == 5):
|
||||||
for char in inputString:
|
for char in inputString:
|
||||||
if(outputType == 1):
|
if(outputType == 1):
|
||||||
@ -35,9 +37,21 @@ def translate(inputString, inputType, outputType):
|
|||||||
result += str(hex(ord(char))) + " "
|
result += str(hex(ord(char))) + " "
|
||||||
else:
|
else:
|
||||||
result = inputString
|
result = inputString
|
||||||
elif (inputType == 1): #binary
|
break
|
||||||
|
return result
|
||||||
|
|
||||||
|
elif(inputType == 1):
|
||||||
inputString = int(inputString, 2)
|
inputString = int(inputString, 2)
|
||||||
if(outputType == 2):
|
elif(inputType == 2):
|
||||||
|
inputString = int(inputString)
|
||||||
|
elif(inputType == 3):
|
||||||
|
inputString = int(inputString, 8)
|
||||||
|
elif(inputType == 4):
|
||||||
|
inputString = int(inputString, 16)
|
||||||
|
|
||||||
|
if(outputType == 1):
|
||||||
|
result = bin(inputString)
|
||||||
|
elif(outputType == 2):
|
||||||
result = inputString
|
result = inputString
|
||||||
elif(outputType == 3):
|
elif(outputType == 3):
|
||||||
result = oct(inputString)
|
result = oct(inputString)
|
||||||
@ -45,54 +59,7 @@ def translate(inputString, inputType, outputType):
|
|||||||
result = hex(inputString)
|
result = hex(inputString)
|
||||||
elif(outputType == 5):
|
elif(outputType == 5):
|
||||||
result = chr(inputString)
|
result = chr(inputString)
|
||||||
elif (inputType == 2):
|
return result
|
||||||
if(outputType == 1):
|
|
||||||
result = bin(inputString)
|
|
||||||
elif(outputType == 2):
|
|
||||||
result = inputString
|
|
||||||
elif(outputType == 3):
|
|
||||||
result = oct(int(inputString))
|
|
||||||
elif(outputType == 4):
|
|
||||||
result = hex(int(inputString))
|
|
||||||
elif(outputType == 5):
|
|
||||||
result = chr(int(inputString))
|
|
||||||
elif (inputType == 3):
|
|
||||||
if(outputType == 1):
|
|
||||||
result = bin(int(inputString, 8))
|
|
||||||
elif(outputType == 2):
|
|
||||||
result = int(inputString, 8)
|
|
||||||
elif(outputType == 3):
|
|
||||||
result = inputString
|
|
||||||
elif(outputType == 4):
|
|
||||||
result = hex(int(inputString, 8))
|
|
||||||
elif(outputType == 5):
|
|
||||||
result = chr(int(inputString, 8))
|
|
||||||
elif (inputType == 4):
|
|
||||||
if(outputType == 1):
|
|
||||||
result = bin(int(inputString,16))
|
|
||||||
elif(outputType == 2):
|
|
||||||
result = int(inputString,16)
|
|
||||||
elif(outputType == 3):
|
|
||||||
result = oct(int(inputString,16))
|
|
||||||
elif(outputType == 4):
|
|
||||||
result = inputString;
|
|
||||||
elif(outputType == 5):
|
|
||||||
result = chr(int(inputString,16))
|
|
||||||
elif (inputType == 5):
|
|
||||||
if(outputType == 1):
|
|
||||||
result = bin(ord(inputString))
|
|
||||||
elif(outputType == 2):
|
|
||||||
result = ord(inputString)
|
|
||||||
elif(outputType == 3):
|
|
||||||
result = oct(ord(inputString))
|
|
||||||
elif(outputType == 4):
|
|
||||||
result = hex(ord(inputString))
|
|
||||||
elif(outputType == 5):
|
|
||||||
result = inputString
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print result
|
|
||||||
|
|
||||||
def rotPrompt():
|
def rotPrompt():
|
||||||
choice = input("What kind of ROT do you want to perform? 1-25, or all: ")
|
choice = input("What kind of ROT do you want to perform? 1-25, or all: ")
|
||||||
@ -118,7 +85,7 @@ def translatePrompt():
|
|||||||
|
|
||||||
inputList = inputString.split(";")
|
inputList = inputString.split(";")
|
||||||
for entry in inputList:
|
for entry in inputList:
|
||||||
translate(entry, inputType, outputType)
|
print(translate(entry, inputType, outputType))
|
||||||
|
|
||||||
def hashPrompt():
|
def hashPrompt():
|
||||||
typeChoice = raw_input('Would you like to hash a file or a String? f for file, s for string: ')
|
typeChoice = raw_input('Would you like to hash a file or a String? f for file, s for string: ')
|
||||||
|
Loading…
Reference in New Issue
Block a user