From 1de9a022bf671fe90ec01330a85dfb2cf202d998 Mon Sep 17 00:00:00 2001 From: panki27 Date: Mon, 23 Oct 2017 12:55:56 +0200 Subject: [PATCH] Initial commit --- README.md | 1 + crypttool.py | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 README.md create mode 100644 crypttool.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..800a249 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# crypttool diff --git a/crypttool.py b/crypttool.py new file mode 100644 index 0000000..451456e --- /dev/null +++ b/crypttool.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python +import sys, string, types, hashlib + +LOWER_LETTERS = [chr(x) for x in range(97, 123)] +UPPER_LETTERS = [chr(x) for x in range(65, 91)] + +def rot(inputString, amount): + outputString = "" + for char in inputString: + resultChar = "" + if char.isupper(): + index = UPPER_LETTERS.index(char) + resultChar = UPPER_LETTERS[(index + amount)%len(UPPER_LETTERS)] + elif char.islower(): + index = LOWER_LETTERS.index(char) + resultChar = LOWER_LETTERS[(index + amount) % len(LOWER_LETTERS)] + else: + resultChar = char + outputString += resultChar + return outputString + +def translate(inputString, inputType, outputType): + result = "" + if (inputType == 5): + for char in inputString: + if(outputType == 1): + result += str(bin(ord(char))) + " " + elif(outputType == 2): + result += str(ord(char)) + " " + elif(outputType == 3): + result += str(oct(ord(char))) + " " + elif(outputType == 4): + result += str(hex(ord(char))) + " " + else: + result = inputString + elif (inputType == 1): #binary + if(outputType == 1): + result = inputString + elif(outputType == 2): + result = int(inputString, 2) + elif(outputType == 3): + result = oct(int(inputString, 2)) + elif(outputType == 4): + result = hex(int(inputString, 2)) + elif(outputType == 5): + result = char(int(inputString, 2)) + elif (inputType == 2): + if(outputType == 1): + result = bin(inputString) + elif(outputType == 2): + result = inputString + elif(outputType == 3): + result = oct(inputString) + elif(outputType == 4): + result = hex(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)) + + print result + +def rotPrompt(): + choice = input("What kind of ROT do you want to perform? 1-25, or all: ") + userInput = raw_input("Please insert a string: ") + if type(choice) is types.IntType: + print(rot(userInput, choice)) + else: + for i in range(0, 26): + print(rot(userInput, i)) + +def translatePrompt(): + print("1: Binary") + print("2: Decimal") + print("3: Octal") + print("4: Hexadecimal") + print("5: ASCII") + inputType = input("Please specify input type: ") + outputType = input("Please specify output type: ") + if (inputType == 5): + inputString = raw_input("Please input your string: ") + else: + inputString = raw_input("Please input your value: ") + + translate(inputString, inputType, outputType) + +def hashPrompt(): + typeChoice = raw_input('Would you like to hash a file or a String? f for file, s for string: ') + algoList = hashlib.algorithms_available + for word in algoList: + print(word) + algoChoice = raw_input('Which hashing algorithm? ') + if algoChoice in algoList: + hasher = hashlib.new(algoChoice) + else: + print("That's no algorithm!") + sys.exit(0) + + if (typeChoice == 'f'): + filePath = raw_input('Please input a fully qualified path: ') + filePath = filePath.strip() + with open(filePath, 'rb') as hashFile: + content = hashFile.read() + hasher.update(content) + else: + inputString = raw_input('Please input a string: ') + hasher.update(inputString) + print(hasher.hexdigest()) + +print("Welcome aboard PankiCrypt Airlines!") +print("How may we serve you today?") +print("1: ROT/Ceasar Encryption") +print("2: Hashing functions") +print("3: Translation") + +choice = input("Please make a selection: ") + +if (choice == 1): + rotPrompt() +elif (choice == 2): + hashPrompt() +elif (choice == 3): + translatePrompt() +print("Thank you for flying with PankiCrypt Airlines!") +