def _start_puzzle(self, ssid): """ Handle the puzzle. Read puzzle from the SSID encrypted with first PreImage, return Puzzle encrypted with first PreImage """ self.startPuzzleTime = time.time() bitSize = ssid.getBitSize() if (bitSize == 0): # No Puzzle required! Connect to network! logging.info("Required Puzzle Size is 0! Not solving Puzzle!") return self.request[1] else: recvhash = bytearray(ssid.getHash()) # received "Hash" logging.debug("Received Hash: %s length: %s" % (recvhash, len(recvhash))) hash2 = bytearray(self.request[1]) # expected Answer logging.debug("Expected hash: %s length: %s" % (hash2, len(hash2))) puzzle = sofi_crypt.xorDecode( recvhash, hash2 ) # decode the received Hash with the expected Hash, this gives us the puzzle. logging.debug("Puzzle received: %s with length: %s" % (puzzle, len(puzzle))) p = sofi_puzzle.mk_preimage_puzzle() start = time.clock() solution = p.solvePuzzleS( puzzle, bitSize=bitSize) # Solve the received Puzzle self.solution = solution logging.debug("Puzzle solved in %.06f seconds." % (time.clock() - start)) logging.debug("Calculated Puzzle Solution: %s" % solution) solEnc = sofi_crypt.xorDecode( solution, hash2 ) # encode the solution with the expected Hash. This is the final ssid. logging.debug("Final search Hash: %s" % solEnc) self.endPuzzleTime = time.time() return solEnc
def _start_puzzle(self,ssid): """ Handle the puzzle. Read puzzle from the SSID encrypted with first PreImage, return Puzzle encrypted with first PreImage """ self.startPuzzleTime = time.time() bitSize = ssid.getBitSize() if(bitSize == 0): # No Puzzle required! Connect to network! logging.info("Required Puzzle Size is 0! Not solving Puzzle!") return self.request[1] else: recvhash = bytearray(ssid.getHash()) # received "Hash" logging.debug("Received Hash: %s length: %s" %(recvhash,len(recvhash))) hash2 = bytearray(self.request[1]) # expected Answer logging.debug("Expected hash: %s length: %s" %(hash2,len(hash2))) puzzle = sofi_crypt.xorDecode(recvhash, hash2) # decode the received Hash with the expected Hash, this gives us the puzzle. logging.debug("Puzzle received: %s with length: %s" %(puzzle,len(puzzle))) p = sofi_puzzle.mk_preimage_puzzle() start = time.clock() solution = p.solvePuzzleS(puzzle,bitSize=bitSize) # Solve the received Puzzle self.solution = solution logging.debug("Puzzle solved in %.06f seconds." %(time.clock()-start)) logging.debug("Calculated Puzzle Solution: %s" %solution) solEnc = sofi_crypt.xorDecode(solution, hash2) # encode the solution with the expected Hash. This is the final ssid. logging.debug("Final search Hash: %s" %solEnc) self.endPuzzleTime = time.time() return solEnc
def main(): logging.basicConfig(filename='sofi_listener.log', level=logging.DEBUG, datefmt='%d.%m %H:%M:%S') logging.info('So-Fi started listening for requests!') database = sofi_db.APdb() puzzler = sofi_puzzle.mk_preimage_puzzle() statelist = [] listener = Listener(database,statelist,puzzler) listener.listen()