def test_part_one(self): "Test part one example of Handshake object" # 1. Create Handshake object from text myobj = handshake.Handshake(text=aoc_25.from_text(PART_ONE_TEXT)) # 2. Check the part one result self.assertEqual(myobj.part_one(verbose=False, limit=99), PART_ONE_RESULT)
def not_test_part_two(self): "Test part two example of Handshake object" # 1. Create Handshake object from text myobj = handshake.Handshake(part2=False, text=aoc_25.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=True, limit=99), PART_TWO_RESULT)
def test_empty_init(self): "Test the default Handshake creation" # 1. Create default Handshake object myobj = handshake.Handshake() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.card_public, None) self.assertEqual(myobj.door_public, None) self.assertEqual(myobj.card_private, None) self.assertEqual(myobj.door_private, None)
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = handshake.Handshake(part2=True, text=input_lines) # 2. Determine the solution for part two solution = solver.part_two(verbose=args.verbose, limit=args.limit) if solution is None: print("There is no solution") else: print("The solution for part two is %s" % (solution)) # 3. Return result return solution is not None
def test_text_init(self): "Test the Handshake object creation from text" # 1. Create Handshake object from text myobj = handshake.Handshake(text=aoc_25.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 2) self.assertEqual(myobj.card_public, 5764801) self.assertEqual(myobj.door_public, 17807724) self.assertEqual(myobj.card_private, None) self.assertEqual(myobj.door_private, None) # 3. Check methods self.assertEqual(myobj.transform_number(17807724, 8), 14897079) self.assertEqual(myobj.transform_number(5764801, 11), 14897079) self.assertEqual(myobj.guess_private(5764801, limit=20), 8) self.assertEqual(myobj.guess_private(17807724, limit=20), 11) self.assertEqual(myobj.guess_encryption_key(verbose=False, limit=20), 14897079)
def __init__(self, port): self.registration = registration.Registration(port) self.handshakePackage = handshake.Handshake(self.registration.addrMe) self.peersLocal = {} self.memPool = {} self.miner = None
return json.dumps(False) @app.route("/ums/changePassword/<netID>/<user>/<hmac>/<time>/") def chPassword(netID, user, hmac, time): if handshake.verify(netID, user, hmac, time): password = acctMgr.mkPassword() if acctMgr.chPassword(user, password): handshake.sendPassword(netID, user, password) return "Your password has been emailed to you" else: return "Your password could not be reset, please try again later" else: return "An error occured, perhaps you have an old link?" # ------------- Begin Program Setup -------------- # Perform global config loading config = init() # Create core objects validate = validate.Validate(config) handshake = handshake.Handshake(config) acctMgr = accountServices.Manager(config) # If we're being loaded without uwsgi, configure the internal server if __name__ == "__main__": host = config["SETTINGS"]["serverAddr"].split(":")[0] port = int(config["SETTINGS"]["serverAddr"].split(":")[1]) or 5000 app.run(host, port)