Last active
August 2, 2026 16:51
-
-
Save bananu7/81b29a691e1113449d6df82b0d762339 to your computer and use it in GitHub Desktop.
Skrypt do szukania ksiąg wieczystych
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import argparse | |
| weights = { | |
| "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, | |
| "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, | |
| "X": 10, "A": 11, "B": 12, "C": 13, "D": 14, | |
| "E": 15, "F": 16, "G": 17, "H": 18, "I": 19, | |
| "J": 20, "K": 21, "L": 22, "M": 23, "N": 24, | |
| "O": 25, "P": 26, "R": 27, "S": 28, "T": 29, | |
| "U": 30, "W": 31, "Y": 32, "Z": 33, | |
| } | |
| biases = [1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7] | |
| def compute_control(kw_str): | |
| total = 0 | |
| for i in range(12): | |
| total += biases[i] * weights[kw_str[i]] | |
| return total % 10 | |
| def generate(n, expected_control): | |
| for last_digit in range(10): | |
| act_n = n * 10 + last_digit | |
| serial = f"{act_n:08d}" | |
| if compute_control("GD1Y" + serial) == expected_control: | |
| yield f"GD1Y/{serial}/{expected_control}" | |
| def gen_between(start, end, expected_control): | |
| for i in range(start, end + 1): | |
| yield from generate(i, expected_control) | |
| def control_digit(value): | |
| value = int(value) | |
| if not 0 <= value <= 9: | |
| raise argparse.ArgumentTypeError( | |
| "control digit must be between 0 and 9" | |
| ) | |
| return value | |
| def prefix(value): | |
| if not (0 <= int(value) <= 9999999): | |
| raise argparse.ArgumentTypeError( | |
| "start/end must be a 7-digit prefix (0-9999999)" | |
| ) | |
| return int(value) | |
| def main(): | |
| parser = argparse.ArgumentParser( | |
| description="Search GD1Y numbers by 7-digit prefix and control digit." | |
| ) | |
| parser.add_argument( | |
| "start", | |
| type=prefix, | |
| help="First 7-digit prefix to search (e.g. 1234567)" | |
| ) | |
| parser.add_argument( | |
| "end", | |
| type=prefix, | |
| help="Last 7-digit prefix to search (inclusive)" | |
| ) | |
| parser.add_argument( | |
| "-c", "--control", | |
| type=control_digit, | |
| required=True, | |
| help="Known control digit (0-9)" | |
| ) | |
| args = parser.parse_args() | |
| if args.start > args.end: | |
| parser.error("start must not be greater than end") | |
| for number in gen_between(args.start, args.end, args.control): | |
| print(number) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment