working zero width text hiding yay

py3
7 years ago
commit e425c271c9

@ -1,323 +1,329 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys, string, types, hashlib, base64, re, urllib, binascii import sys, string, types, hashlib, base64, re, urllib, binascii
import operator import operator
from collections import Counter from collections import Counter
LOWER_LETTERS = [chr(x) for x in range(97, 123)] LOWER_LETTERS = [chr(x) for x in range(97, 123)]
UPPER_LETTERS = [chr(x) for x in range(65, 91)] UPPER_LETTERS = [chr(x) for x in range(65, 91)]
COMMON_LETTERS = 'ETAOIN SHRDLU' COMMON_LETTERS = 'ETAOIN SHRDLU'
def xorRepeating(): def xorRepeating():
plain = raw_input('Please input your Plaintext: ') plain = raw_input('Please input your Plaintext: ')
key = raw_input('Key: ') key = raw_input('Key: ')
hexkey = list() hexkey = list()
i = 0 i = 0
for c in key: for c in key:
print(i) print(i)
hexkey.append(ord(c)) hexkey.append(ord(c))
i += 1 i += 1
resultString = '' resultString = ''
i = 0 i = 0
for char in plain: for char in plain:
resultString += str(hex(ord(char) ^ hexkey[i]))[2:] resultString += str(hex(ord(char) ^ hexkey[i]))[2:]
i += 1 i += 1
if i == len(key): if i == len(key):
i = 0 i = 0
print(resultString) print(resultString)
def xorBrutePrompt(): def xorBrutePrompt():
isfile = (raw_input('f for file; for string:') == 'f') isfile = (raw_input('f for file; for string:') == 'f')
maxresults = input('How many top hits? ') maxresults = input('How many top hits? ')
keylength = input('Maximum key length in bytes: ') keylength = input('Maximum key length in bytes: ')
if isfile: if isfile:
path = raw_input('path: ') path = raw_input('path: ')
path = path.strip() path = path.strip()
results = list() results = list()
with open(path, 'r') as file: with open(path, 'r') as file:
contents = file.readlines() contents = file.readlines()
contents = [line.strip() for line in contents] contents = [line.strip() for line in contents]
for code in contents: for code in contents:
recursiveResult = xorSingleBrute(code, maxresults, keylength) recursiveResult = xorSingleBrute(code, maxresults, keylength)
#nach Punkten aufsteigend sortieren: #nach Punkten aufsteigend sortieren:
sortedList = sorted(recursiveResult.items(), key=operator.itemgetter(1))[-maxresults:] sortedList = sorted(recursiveResult.items(), key=operator.itemgetter(1))[-maxresults:]
#Liste in maximalwert dieser als Tupel anhaengen: #Liste in maximalwert dieser als Tupel anhaengen:
results.append((sortedList, max(recursiveResult.iteritems(), key=operator.itemgetter(1))[1])) results.append((sortedList, max(recursiveResult.iteritems(), key=operator.itemgetter(1))[1]))
#sortieren nach MaxWert: #sortieren nach MaxWert:
sortedResults = sorted(results, key=operator.itemgetter(1)) sortedResults = sorted(results, key=operator.itemgetter(1))
for item in sortedResults: for item in sortedResults:
#da tupel muss so iteriert werden: #da tupel muss so iteriert werden:
for tupel in item[::2]: for tupel in item[::2]:
for i in tupel: for i in tupel:
print(i[0]) print(i[0])
else: else:
encoded = raw_input('Input your Hex String: ') encoded = raw_input('Input your Hex String: ')
result = xorSingleBrute(encoded, maxresults, keylength) result = xorSingleBrute(encoded, maxresults, keylength)
sortedResults = sorted(result.items(), key=operator.itemgetter(1))[-maxresults:] sortedResults = sorted(result.items(), key=operator.itemgetter(1))[-maxresults:]
for i, j in sortedResults: for i, j in sortedResults:
print(i) print(i)
def xorSingleBrute(encoded='', maxresults=20, keybytes=1): def xorSingleBrute(encoded='', maxresults=20, keybytes=1):
resultDict = dict() resultDict = dict()
if(encoded == ''): if(encoded == ''):
isfile = (raw_input('f for file; for string:') == 'f') isfile = (raw_input('f for file; for string:') == 'f')
for xor_key in range(0, 2**(keybytes*8)): for xor_key in range(0, 2**(keybytes*8)):
decoded = ''; decoded = '';
for i, j in zip(encoded[::2], encoded[1::2]): for i, j in zip(encoded[::2], encoded[1::2]):
decoded += ''.join(chr(int(i+j, 16) ^ xor_key)) decoded += ''.join(chr(int(i+j, 16) ^ xor_key))
resultDict[decoded] = commonCounter(decoded) resultDict[decoded] = commonCounter(decoded)
return resultDict return resultDict
def commonCounter(inputString, limit=7): def commonCounter(inputString, limit=7):
countObj = Counter(inputString.upper()) countObj = Counter(inputString.upper())
common = countObj & Counter(COMMON_LETTERS) common = countObj & Counter(COMMON_LETTERS)
return sum(common.values()) return sum(common.values())
def fixedxor(string1 = '', string2 = ''): def fixedxor(string1 = '', string2 = ''):
if(string1 == ''): if(string1 == ''):
string1 = raw_input('Please input your first hex string: ') string1 = raw_input('Please input your first hex string: ')
string2 = raw_input('Please input your second hex string: ') string2 = raw_input('Please input your second hex string: ')
hex1 = int(string1, 16) hex1 = int(string1, 16)
hex2 = int(string2, 16) hex2 = int(string2, 16)
result = hex1 ^ hex2 result = hex1 ^ hex2
print(hex(result)) print(hex(result))
def rot(inputString, amount): def rot(inputString, amount):
outputString = '' outputString = ''
for char in inputString: for char in inputString:
resultChar = '' resultChar = ''
if char.isupper(): if char.isupper():
index = UPPER_LETTERS.index(char) index = UPPER_LETTERS.index(char)
resultChar = UPPER_LETTERS[(index + amount)%len(UPPER_LETTERS)] resultChar = UPPER_LETTERS[(index + amount)%len(UPPER_LETTERS)]
elif char.islower(): elif char.islower():
index = LOWER_LETTERS.index(char) index = LOWER_LETTERS.index(char)
resultChar = LOWER_LETTERS[(index + amount) % len(LOWER_LETTERS)] resultChar = LOWER_LETTERS[(index + amount) % len(LOWER_LETTERS)]
else: else:
resultChar = char resultChar = char
outputString += resultChar outputString += resultChar
return outputString return outputString
def translate(inputString, inputType, outputType): def translate(inputString, inputType, outputType):
result = '' result = ''
if(inputType == outputType): if(inputType == outputType):
result = inputString result = inputString
return result return result
if (inputType == 5): if (inputType == 5):
for char in inputString: for char in inputString:
if(outputType == 1): if(outputType == 1):
result += bin(ord(char)) + ' ' byte = bin(ord(char))
elif(outputType == 2): while len(byte) < 8:
result += ord(char) + ' ' byte = '0' + byte
elif(outputType == 3): result += byte + ' '
result += oct(ord(char)) + ' '
elif(outputType == 4): elif(outputType == 2):
result += hex(ord(char)) + ' ' result += ord(char) + ' '
else: elif(outputType == 3):
result = inputString result += oct(ord(char)) + ' '
break elif(outputType == 4):
return result result += hex(ord(char)) + ' '
else:
elif(inputType == 1): result = inputString
inputString = int(inputString, 2) break
elif(inputType == 2): return result
inputString = int(inputString)
elif(inputType == 3): elif(inputType == 1):
inputString = int(inputString, 8) inputString = int(inputString, 2)
elif(inputType == 4): elif(inputType == 2):
inputString = int(inputString, 16) inputString = int(inputString)
elif(inputType == 3):
if(outputType == 1): inputString = int(inputString, 8)
result = bin(inputString) elif(inputType == 4):
elif(outputType == 2): inputString = int(inputString, 16)
result = inputString
elif(outputType == 3): if(outputType == 1):
result = oct(inputString) result = bin(inputString)
elif(outputType == 4): elif(outputType == 2):
result = hex(inputString) result = inputString
elif(outputType == 5): elif(outputType == 3):
result = chr(inputString) result = oct(inputString)
return result elif(outputType == 4):
result = hex(inputString)
def zeroWidthString(inputstring): elif(outputType == 5):
resultstring = '>' result = chr(inputString)
binary = translate(inputstring, 5, 1) return result
binaryArray = binary.split(" ")
print (binaryArray) def zeroWidthString(inputstring):
for byte in binaryArray: resultstring = '>'
for bit in byte[2:10]: #binary = translate(inputstring, 5, 1)
if(bit == '1'): binary = string2bin(inputstring)
resultstring+= u'\u200b' #zero-width space binaryArray = split_len(binary, 8)
else: for byte in binaryArray:
resultstring+= u'\u200d' #zero-width joiner for bit in byte:
resultstring += '<' if(bit == '1'):
print resultstring resultstring+= u'\u200b' #zero-width space
else:
def resolveZeroWidthString(inputstring): resultstring+= u'\u200d' #zero-width joiner
charfound = False resultstring += '<'
binarystring = '' print resultstring
resultstring = ''
inputstring = inputstring.decode('unicode-escape') def resolveZeroWidthString(inputstring):
for char in inputstring: charfound = False
print char binarystring = ''
if char == u'\u200b': resultstring = ''
binarystring += '1' inputstring = inputstring.decode('utf-8')
elif char == u'\u200d': for char in inputstring:
binarystring += '0' if char == u'\u200b':
for byte in binarystring[::8]: binarystring += '1'
resultstring += translate(byte, 1, 5) elif char == u'\u200d':
print resultstring binarystring += '0'
bytelist = split_len(binarystring, 8)
def vignere(plain, key): for byte in bytelist:
i = 0 resultstring += translate(byte, 1, 5)
result = '' print resultstring
plain = plain.upper()
key = key.upper() def split_len(seq, length):
for char in plain: return [seq[i:i+length] for i in range(0, len(seq), length)]
if char in UPPER_LETTERS:
result += chr( (((ord(char)) + (ord(key[i])))%26)+65) def vignere(plain, key):
i += 1 i = 0
if (i == len(key)): result = ''
i = 0 plain = plain.upper()
else: key = key.upper()
result += '.' for char in plain:
return result if char in UPPER_LETTERS:
result += chr( (((ord(char)) + (ord(key[i])))%26)+65)
def string2bin(input): i += 1
return ''.join(format(ord(x), 'b').zfill(8) for x in input) if (i == len(key)):
i = 0
def hammingDistance(string1, string2): else:
diffs = 0 result += '.'
bin1 = string2bin(string1) return result
bin2 = string2bin(string2)
for b1, b2 in zip(bin1, bin2): def string2bin(input):
if b1 != b2: return ''.join(format(ord(x), 'b').zfill(8) for x in input)
diffs += 1
return diffs def hammingDistance(string1, string2):
diffs = 0
def urlEncoder(): bin1 = string2bin(string1)
input = raw_input('Pleae input your String: ') bin2 = string2bin(string2)
print(urllib.quote_plus(input)) for b1, b2 in zip(bin1, bin2):
if b1 != b2:
def reverser(): diffs += 1
string = raw_input('Please input your string to reverse:') return diffs
print(string[::-1])
def urlEncoder():
def base64prompt(): input = raw_input('Pleae input your String: ')
b64regex = '^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$' print(urllib.quote_plus(input))
isfile = (raw_input('f for file, s for string: ') == 'f')
if isfile: def reverser():
path = raw_input('Path: ') string = raw_input('Please input your string to reverse:')
path = path.strip() print(string[::-1])
outputPath = raw_input('Output file: ')
with open(path, 'r') as file: def base64prompt():
contents = file.read() b64regex = '^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$'
file.close() isfile = (raw_input('f for file, s for string: ') == 'f')
#contents = [line.strip() for line in contents] if isfile:
decoded = base64.b64decode(contents) path = raw_input('Path: ')
with open(outputPath, 'w') as outfile: path = path.strip()
#for line in contents: outputPath = raw_input('Output file: ')
outfile.write(decoded) with open(path, 'r') as file:
outfile.close() contents = file.read()
else: file.close()
inputString = raw_input('Please input your string: ') #contents = [line.strip() for line in contents]
if (re.match(b64regex, inputString)): decoded = base64.b64decode(contents)
print(base64.b64decode(inputString)) with open(outputPath, 'w') as outfile:
else: #for line in contents:
print(base64.b64encode(inputString)) outfile.write(decoded)
outfile.close()
else:
def rotPrompt(): inputString = raw_input('Please input your string: ')
choice = input('What kind of ROT do you want to perform? 1-25, or all: ') if (re.match(b64regex, inputString)):
userInput = raw_input('Please insert a string: ') print(base64.b64decode(inputString))
if type(choice) is types.IntType: else:
print(rot(userInput, choice)) print(base64.b64encode(inputString))
else:
for i in range(0, 26):
print(rot(userInput, i)) def rotPrompt():
choice = input('What kind of ROT do you want to perform? 1-25, or all: ')
def translatePrompt(): userInput = raw_input('Please insert a string: ')
print('1: Binary') if type(choice) is types.IntType:
print('2: Decimal') print(rot(userInput, choice))
print('3: Octal') else:
print('4: Hexadecimal') for i in range(0, 26):
print('5: ASCII') print(rot(userInput, i))
inputType = input('Please specify input type: ')
outputType = input('Please specify output type: ') def translatePrompt():
if (inputType == 5): print('1: Binary')
inputString = raw_input('Please input your strings, seperated by semicolon: ') print('2: Decimal')
else: print('3: Octal')
inputString = raw_input('Please input your values, seperated by semicolon: ') print('4: Hexadecimal')
print('5: ASCII')
inputList = inputString.split(';') inputType = input('Please specify input type: ')
for entry in inputList: outputType = input('Please specify output type: ')
print(str(translate(entry, inputType, outputType))) if (inputType == 5):
inputString = raw_input('Please input your strings, seperated by semicolon: ')
def hashPrompt(): else:
typeChoice = raw_input('Would you like to hash a file or a String? f for file, s for string: ') inputString = raw_input('Please input your values, seperated by semicolon: ')
algoList = hashlib.algorithms_available
for word in algoList: inputList = inputString.split(';')
print(word) for entry in inputList:
algoChoice = raw_input('Which hashing algorithm? ') print(str(translate(entry, inputType, outputType)))
if algoChoice in algoList:
hasher = hashlib.new(algoChoice) def hashPrompt():
else: typeChoice = raw_input('Would you like to hash a file or a String? f for file, s for string: ')
print('That\'s no algorithm!') algoList = hashlib.algorithms_available
sys.exit(0) for word in algoList:
print(word)
if (typeChoice == 'f'): algoChoice = raw_input('Which hashing algorithm? ')
filePath = raw_input('Please input a fully qualified path: ') if algoChoice in algoList:
filePath = filePath.strip() hasher = hashlib.new(algoChoice)
with open(filePath, 'rb') as hashFile: else:
content = hashFile.read() print('That\'s no algorithm!')
hasher.update(content) sys.exit(0)
else:
inputString = raw_input('Please input a string: ') if (typeChoice == 'f'):
hasher.update(inputString) filePath = raw_input('Please input a fully qualified path: ')
print(hasher.hexdigest()) filePath = filePath.strip()
with open(filePath, 'rb') as hashFile:
print('Welcome aboard PankiCrypt Airlines!') content = hashFile.read()
print('How may we serve you today?') hasher.update(content)
print('1: ROT/Ceasar Encryption') else:
print('2: Hashing functions') inputString = raw_input('Please input a string: ')
print('3: Translation') hasher.update(inputString)
print('4: Base64 Encoder/Decoder') print(hasher.hexdigest())
print('5: String Reverser')
print('6: URL Encoder') print('Welcome aboard PankiCrypt Airlines!')
print('7: Fixed XOR') print('How may we serve you today?')
print('8: XOR Bruteforce Single Byte ') print('1: ROT/Ceasar Encryption')
print('9: XOR Repeating Key') print('2: Hashing functions')
print('10: Zero-Width String') print('3: Translation')
print('11: Resolve Zero-Width Strings') print('4: Base64 Encoder/Decoder')
choice = raw_input('Please make a selection: ') print('5: String Reverser')
if (choice == '1'): print('6: URL Encoder')
rotPrompt() print('7: Fixed XOR')
elif (choice == '2'): print('8: XOR Bruteforce Single Byte ')
hashPrompt() print('9: XOR Repeating Key')
elif (choice == '3'): print('10: Zero-Width String')
translatePrompt() print('11: Resolve Zero-Width Strings')
elif(choice == '4'): choice = raw_input('Please make a selection: ')
base64prompt() if (choice == '1'):
elif(choice == '5'): rotPrompt()
reverser() elif (choice == '2'):
elif(choice == '6'): hashPrompt()
urlEncoder() elif (choice == '3'):
elif(choice[0] == '7'): translatePrompt()
if(len(choice) > 1): elif(choice == '4'):
argList = choice.split(' ') base64prompt()
fixedxor(argList[1], argList[2]) elif(choice == '5'):
else: reverser()
fixedxor() elif(choice == '6'):
elif(choice == '8'): urlEncoder()
#xorSingleBrute() elif(choice[0] == '7'):
xorBrutePrompt() if(len(choice) > 1):
elif(choice == '9'): argList = choice.split(' ')
xorRepeating() fixedxor(argList[1], argList[2])
elif(choice == '10'): else:
i = raw_input('String:') fixedxor()
zeroWidthString(i) elif(choice == '8'):
elif(choice == '11'): #xorSingleBrute()
i = raw_input('String:') xorBrutePrompt()
resolveZeroWidthString(i) elif(choice == '9'):
print('Thank you for flying with PankiCrypt Airlines!') xorRepeating()
elif(choice == '10'):
i = raw_input('String:')
zeroWidthString(i)
elif(choice == '11'):
i = raw_input('String:')
resolveZeroWidthString(i)
print('Thank you for flying with PankiCrypt Airlines!')
Loading…
Cancel
Save