def on_think(self): if self.state is walking: if 0: # not self.path: self.say("Whoops! I'm a bit lost now...") mud.log("Sarin: walking without a path") self.state = idle return if self.state is talking: pass if self.state is idle: if(self.location.vnum == sarins_room): if( random.randint(0, 10) == 1 ): if self.lastseen_healer + 10 < mud.ticks(): self.setPath("ddwn") elif self.lastseen_priest + 10 < mud.ticks(): self.setPath("ddwwn") if self.path: self.state = walking self.say("Hmm, I guess I should walk around now ...") elif(self.location.vnum == chamber): self.lastseen_priest = mud.ticks() if( random.randint(0, 5) == 1 ): self.say("Hmm, I guess I should leave now ...") self.state = walking if self.lastseen_healer + 4 < mud.ticks(): self.setPath("sen") else: self.setPath("seeuu") elif(self.location.vnum == altar): self.lastseen_healer = mud.ticks() if( random.randint(0, 5) == 1 ): self.say("Hmm, I guess I should leave now ...") self.state = walking if self.lastseen_priest + 4 < mud.ticks(): self.setPath("swn") else: self.setPath("seu") else: # whoops! okay, go back to my room self.state = walking self.setPath(sarins_room) self.say("Whoa, what was I doing?") self.say("I better head back to my room.")
def __init__(self, p=IETF_PRIME, g=2, private_key=None): self.p = p if private_key is None: self._private_key = random.randint(1, p - 1) else: self._private_key = private_key self.public_key = pow(g, self._private_key, p) self._shared_keys = {} self.inbox = defaultdict(list)
def _respond_to_login_request(self, username, A, k=3): if k != 0: raise ValueError("k must be 0") salt, _, _ = self.real_server._respond_to_login_request(username, A, k=k) b = random.randint(1, IETF_PRIME - 1) self.users[username] = {"salt": salt, "A": A, "b": b} u = 1 B = pow(self.g, b, IETF_PRIME) return (salt, B, u)
def __get_stepcontent_point(self): """ 生成一个步速采样点 由步数生成时间 """ step_count = random.randint(9, 12) # 一次 9 - 12 步 step_time = step_count / self.stride_frequncy * 60 step_time *= (1.0 + (random.random() - 0.5) * 2 * 0.05) # 引入 5% 的速率浮动 return [step_count, round(step_time, 2)] # 时间取 2 位小数
def _respond_to_login_request(self, username, A, k=3): # A == public ephemeral number from client user = self.users[username] b = random.randint(1, IETF_PRIME - 1) # private ephemeral number # B == public ephemeral number. Usually, B depends on the password, but # if k == 0, it is a completely random Diffie-Hellman public key, which # causes u to be essentially random. B = ((k * user["verifier"]) + pow(self.g, b, IETF_PRIME)) % IETF_PRIME u = scramble_keys(A, B) S = pow(A * pow(user["verifier"], u, IETF_PRIME), b, IETF_PRIME) user["shared_session_key"] = sha256(int_to_bytes(S)).digest() return (user["salt"], B, u)
def log_in(self, server, username, password, k=3): a = random.randint(1, IETF_PRIME - 1) # private ephemeral number A = pow(self.g, a, IETF_PRIME) # public ephemeral number # B == public ephemeral number from server salt, B, u = server._respond_to_login_request(username, A, k=k) # TODO: figure out if it is possible to make the offline attack work if # the following line is uncommented # assert u == scramble_keys(A, B) x = generate_private_key(username, password, salt) S = pow(B - k * pow(self.g, x, IETF_PRIME), a + u*x, IETF_PRIME) shared_session_key = sha256(int_to_bytes(S)).digest() # called "K" in challenge hmac = calculate_hmac(shared_session_key, salt, sha256) return server._verify_hmac(hmac, username)
def sign_and_leak_k(message, private_key, g=g, secure=True): # Setting secure to False will prevent this function from retrying the # signature if r == 0, which may happen with invalid signatures, if g is # maliciously chosen, or on other rare occasions. digest = int.from_bytes(sha1(message).digest(), byteorder="big") while True: # k == random, per-message number that must be secret k = random.randint(1, q - 1) r = pow(g, k, p) % q if secure and r == 0: continue s = (mod_inv(k, q) * (digest + r*private_key)) % q if s == 0: continue return (Signature(r, s), k)
def simAnnelSearch(problem): from game import Directions from util import random directionTable = { 'South': Directions.SOUTH, 'North': Directions.NORTH, 'West': Directions.WEST, 'East': Directions.EAST } startState = problem.getStartState() list = util.PriorityQueue() visited = set() list.push((startState, []), 0) while not list.isEmpty(): nextNode = list.pop() actualState = nextNode[0] direct = nextNode[1] cost = 0 hn = 0 low_h = manhattanHeuristic(startState, problem, 0) low_state = nextNode[0] low_action = nextNode[1] if problem.isGoalState(actualState): cost = problem.getCostOfActions(direct) print "Total cost:" + str(cost) return direct if actualState not in visited: visited.add(actualState) for i in problem.getSuccessors(actualState): hn = manhattanHeuristic(i[0], problem, 0) if hn <= low_h: low_h = hn low_state = i[0] low_action = i[1] else: k = problem.getSuccessors(actualState) j = k[random.randint(0, len(k) - 1)] low_action = j[1] if i[0] not in visited: list.push((low_state, direct + [directionTable[str(low_action)]]), 0)
def on_detectEntry(self, ch): if ch.isNPC: if (ch.vnum == 9708): self.say("How'ya doing, Sar'n?") return if self.memory.has_key(ch.id): elapsed = mud.ticks() - self.memory[ch.id].last_seen else: self.memory[ch.id] = Memory(ch) elapsed = 100 if ch.isPet: if elapsed > 2: self.do("pat " + ch.name) else: if self.memory.has_key(ch.id): elapsed = mud.ticks() - self.memory[ch.id].last_seen if elapsed > 50: self.say("Hey, haven't seen you around much, " + self.pers(ch) + ".") elif elapsed > 15: self.say("Hey, welcome back! Wow, it's been like ..." " %d hours? " % elapsed) elif elapsed > 5: self.say("Hi again, " + self.pers(ch) + "!") elif elapsed > 2: self.do("smile " + ch.name) else: self.memory[ch.id] = Memory(ch) self.say("Hi, " + self.pers(ch) + "!") if random.randint(0, 6) == 5 and not ch.isNPC: self.praise_eq(ch) self.memory[ch.id].last_seen = mud.ticks()
def on_detectEntry(self, ch): if ch.isNPC: if(ch.vnum == 9708): self.say("How'ya doing, Sar'n?"); return if self.memory.has_key(ch.id): elapsed = mud.ticks() - self.memory[ch.id].last_seen else: self.memory[ch.id] = Memory(ch) elapsed = 100 if ch.isPet: if elapsed > 2: self.do("pat " + ch.name) else: if self.memory.has_key(ch.id): elapsed = mud.ticks() - self.memory[ch.id].last_seen if elapsed > 50: self.say("Hey, haven't seen you around much, " + self.pers(ch) + ".") elif elapsed > 15: self.say("Hey, welcome back! Wow, it's been like ..." " %d hours? " % elapsed) elif elapsed > 5: self.say("Hi again, " + self.pers(ch) + "!") elif elapsed > 2: self.do("smile " + ch.name) else: self.memory[ch.id] = Memory(ch) self.say("Hi, " + self.pers(ch) + "!") if random.randint(0, 6) == 5 and not ch.isNPC: self.praise_eq(ch) self.memory[ch.id].last_seen = mud.ticks()
def random(cls): private_key = random.randint(1, q - 1) # called "x" in literature public_key = pow(g, private_key, p) # called "y" in literature return cls(public_key, private_key)
def on_think(self): if random.randint(0, 15) < 13: return
def __node_second_delta(self): """ 生成节点秒数随机偏移量 """ return random.randint(-10, 10) # 上下浮动 10s
def __upload_delay(self): """ 生成 上传记录 与 结束跑步 之间的时间间隔 """ return random.randint(10, 20) # 10~20s 的间隔