From abfc5cc8172f9bba7eb8ce2a8964d0eb8a574c03 Mon Sep 17 00:00:00 2001 From: Guanforever <2307786059@qq.com> Date: Thu, 3 Jul 2025 18:38:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=86=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- guess copy.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 guess copy.py diff --git a/guess copy.py b/guess copy.py new file mode 100644 index 0000000..2744440 --- /dev/null +++ b/guess copy.py @@ -0,0 +1,70 @@ +def generate_clue_file(output_path="clue.json"): + """ + 生成包含密码线索和哈希值的 JSON 文件 + 包含 1~3 个合法线索条件(基于真实密码内容) + """ + password = generate_random_password() + lock = PasswordLock() + stored_hash = lock.hash_password(password) + digits = list(map(int, password)) + + conditions = [] + + # 判断是否满足 [-1, -1] 条件 + satisfy_prime_unique = satisfies_prime_unique_condition(digits) + + # 线索种类池 + available_methods = [1, 2] + if satisfy_prime_unique: + available_methods.append(3) # 添加 [-1, -1] 的机会 + + # 随机生成 1~3 个线索 + num_conditions = random.randint(1, 3) + used_positions = set() # 已使用的位置(避免重复添加相同位置的奇偶性) + + for _ in range(num_conditions): + method = random.choice(available_methods) + + if method == 1: # [a, t]: 奇偶性判断 + while True: + pos = random.randint(1, 3) + if pos not in used_positions: + break + digit = digits[pos - 1] + parity = digit % 2 # 根据实际奇偶性生成 + conditions.append([pos, parity]) + used_positions.add(pos) + + elif method == 2: # [x, y, z]: 固定某位数字 + while True: + idx = random.randint(0, 2) + if idx not in used_positions: + break + cond = [-1, -1, -1] + cond[idx] = digits[idx] + conditions.append(cond) + used_positions.add(idx) + + elif method == 3: # [-1, -1]: 每位为素数且不重复 + if satisfy_prime_unique and [-1, -1] not in conditions: + conditions.append([-1, -1]) + + # 至少保留一个线索 + if not conditions: + return generate_clue_file(output_path) + + # 写入文件 + clue_data = { + "C": conditions, + "L": stored_hash + } + + with open(output_path, 'w', encoding='utf-8') as f: + json.dump(clue_data, f, ensure_ascii=False, indent=4) + + print(f"已生成线索文件: {output_path}") + print(f"原始密码: {password}") + print(f"线索内容: {conditions}") + print(f"哈希值: {stored_hash}") + + return password, conditions, stored_hash \ No newline at end of file