import os import sys import time import random import hashlib import itertools from base64 import b64encode as b64enc, b64decode as b64dec BS = 16 iv = "0"*BS # set to "" if not known class bc: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' def p(t): sys.stdout.write(t) s = "" def printScreen(enc,dec,match,status="",less=False): if less and random.random()maxLen: break for ni,n in enumerate(b): if dec[bi][ni]=="0": if match!=0: matchInds = [] for m in match[ni]: for i in m[1]: matchInds.append(i) if bi in matchInds: #p(bc.OKBLUE+b64enc(n)[0]+bc.ENDC) p(b64enc(n)[0]) else: #p(b64enc(n)[0]) p(bc.FAIL+"#"+bc.ENDC) else: p(bc.OKGREEN+dec[bi][ni]+bc.ENDC) print("\n\n"+s+"\n\n") #time.sleep(0.01) def cls(): os.system('cls' if os.name=='nt' else 'clear') def sxor(s1,s2): return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1,s2)) def main(enc): c = [list(enc[i*BS:][:BS]) for i in range(int(ceil(float(len(enc))/BS)))] enc = c dec = [] for i in enc: dec.append(["0"]*BS) printScreen(enc,dec,0,"Cross-Entropy-Mapping") # nugget 1 nugget 2 # [ [[char,block],...] , [...] , ... ] seen = [] # nugget 1 nugget 2 # [ [[char,[index1,index2,...],...] , [...] , ... ] match = [] # [[clash,indN,indA,indB],...] tron = [] for i in range(BS): match.append([]) seen.append([]) for bi,b in enumerate(enc): #for every block for ni,n in enumerate(b): #for every nugget for mi,m in enumerate(match[ni]): if m[0]==n: # Match already exists, add our new one m[1].append(bi) # add our Block-Index to the Match printScreen(enc,dec,match,"",2) break else: # No existing Match found; Searching for new one for si,s in enumerate(seen[ni]): if s[0]==n: #Found dat Match # char,[bIndex Seen, bIndex New] match[ni].append([n,[s[1],bi]]) printScreen(enc,dec,match,"",2) break else: # No Match, Char not in seen # char, bIndex seen[ni].append([n,bi]) printScreen(enc,dec,match,"Calculating Trons...") for ni,n in enumerate(match): #for every nugget for mi,m in enumerate(n): #for every match for indexA,indexB in itertools.combinations(m[1],2): #for every bIndex-Pair if indexA==0: if len(iv)!=0: tron.append([ sxor(enc[indexB-1][ni],iv), ni, [indexA, indexB]]) else: tron.append([ sxor(enc[indexA-1][ni],enc[indexB-1][ni]), ni, [indexA, indexB]]) printScreen(enc,dec,match,"Constructing Matrix") matrix = [] for i in range(len(enc)*BS): matrix.append([]) for j in range(128): matrix[i] = [1]*128 printScreen(enc,dec,match,"Planting Seeds...") for ti,t in enumerate(tron): bin = '{0:07b}'.format(ord(t[0])) for b in [0,1]: if bin[:2]=="00": # is 00****** # but to be valid, it has to be 001***** -> min 32 for i in range(32): matrix[t[2][b]*8+t[1]][i] = 0 elif bin[:2]=="10": # is 10****** # first bit is not allowes to flip for i in range(64,128): matrix[t[2][b]*8+t[1]][i] = 0 elif bin[:2]=="11": # is 11****** # first 2 bits are not allowes to flip for i in range(96,128): matrix[t[2][b]*8+t[1]][i] = 0 elif bin[:2]=="01": # is 01****** # second bit is only allowed to flip, # if first bit flips for i in range(32,64): matrix[t[2][b]*8+t[1]][i] = 0 legals = [] legals.append([45,46,47]) legals.append(range(65,90)) legals.append([95]) legals.append([97,122]) tronHistory = [] printScreen(enc,dec,match,"Growing Seeds...") while True: p(".") hash = hashlib.sha256(str(tron)).hexdigest() if hash in tronHistory: break tronHistory.append(hash) for ti,t in enumerate(tron): for direction in [0,1]: for possibilityA,avaibleA in enumerate(matrix[t[2][direction]*8+t[1]]): if avaibleA: for possibilityB,avaibleB in enumerate(matrix[t[2][direction]*8+t[1]]): if avaibleB: if (possibilityA ^ possibilityB) not in legals: matrix[t[2][direction]*8+t[1]][possibilityA] = 0 matrix[t[2][direction]*8+t[1]][possibilityB] = 0 for m in matrix: l = 0 for i in m: if i: l+=1 if l==1: print("Yay!") if __name__=="__main__": from lazarus import * lazarus = Lazarus("This is a safe Password") knownDec = "This is a very very long text message, that I use to text my text. If you read this text, dont think it is your text just because you read it, it is still my text! So: Fuck of and get you own text, if you want one, asshole..."*200 enc = lazarus.enc(knownDec) main(enc)