From 0abaebb2e81281686a7c697da7e5d35c05d173e7 Mon Sep 17 00:00:00 2001 From: ross Date: Mon, 25 Oct 2021 13:34:39 +0100 Subject: [PATCH] debugging fully removed, Table working --- src/rainbow_generator.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/rainbow_generator.py b/src/rainbow_generator.py index 60c0c14..f7eca10 100644 --- a/src/rainbow_generator.py +++ b/src/rainbow_generator.py @@ -20,7 +20,7 @@ def targetHashFunction(value): return h -def makeGuess(value, i, minLen,maxLen,charset, debug=True): +def makeGuess(value, i, minLen,maxLen,charset, debug=False): """ Given a value and an index, return a new valid input. Arguments: @@ -50,7 +50,7 @@ def makeGuess(value, i, minLen,maxLen,charset, debug=True): -def queryTable(hashValue,table, chainLength, hashFunc=targetHashFunction, guessFunc=makeGuess, minLen=3, maxLen=6, charset=defaultCharset, debug=True): +def queryTable(hashValue,table, chainLength, hashFunc=targetHashFunction, guessFunc=makeGuess, minLen=3, maxLen=6, charset=defaultCharset, debug=False): """find a chain that contains an input value that results in the given hash, in the given table. chainLength limits the search since there is no point building test chains longer than the ones in the @@ -85,10 +85,9 @@ def queryTable(hashValue,table, chainLength, hashFunc=targetHashFunction, guessF h=hashFunc(g) if debug: out+=f"({g}->{h}) " if debug: print(out) - print(h) if h in table: if debug: print(f"Found hash in chain at position {i}, beginning with {table[h]}") - attempt= rebuildChain(table[h],hashValue, hashFunc, guessFunc, chainLength,minLen, maxLen, charset, debug=True) + attempt= rebuildChain(table[h],hashValue, hashFunc, guessFunc, chainLength,minLen, maxLen, charset, debug=False) if attempt!=None: return attempt if debug: print("No matches found") @@ -96,7 +95,7 @@ def queryTable(hashValue,table, chainLength, hashFunc=targetHashFunction, guessF -def rebuildChain(chain,targetHash, hashFunc, guessFunc, chainLength,minLen, maxLen, charset, debug=True): +def rebuildChain(chain,targetHash, hashFunc, guessFunc, chainLength,minLen, maxLen, charset, debug=False): """ Recreates a single chain, looking for a target hash. Arguments: @@ -145,7 +144,6 @@ def generateTable(chainStarts, hashFunc, guessFunc, chainLength, minLen=3,maxLen tempHash= targetHashFunction(tempAnswer) # creating a temp hash with the current guess tempAnswer = makeGuess(tempHash, j, minLen, maxLen, charset) # making a guess using the curennt hash by calling makeGuess with all parameters note: J is how far along in the chain the code is RainbowTable.update({tempHash: i}) #adds the first guess and last hash a value key pair - print(RainbowTable.keys()) return RainbowTable