diff --git a/decode.py b/decode.py new file mode 100644 index 0000000..5fc64ec --- /dev/null +++ b/decode.py @@ -0,0 +1,32 @@ +def main(): + field_map = { + 'A': 0, 'a': 1, 'B': 2, 'b': 3, + 'C': 4, 'c': 5, 'D': 6, 'd': 7, + '1': 8, 'E': 9, 'e': 10, 'F': 11, + 'f': 12, 'G': 13, 'g': 14, 'H': 15, + 'h': 16, '2': 17, 'I': 18, 'i': 19, + 'J': 20, 'j': 21, 'K': 22, 'k': 23, + 'L': 24, 'l': 25, '3': 26, 'M': 27, + 'm': 28, 'N': 29, 'n': 30, 'O': 31, + 'o': 32, 'P': 33, 'p': 34, '4': 35, + 'Q': 36, 'q': 37, 'R': 38, 'r': 39, + 'S': 40, 's': 41, 'T': 42, 't': 43, + '5': 44, 'U': 45, 'u': 46, 'V': 47, + 'v': 48, 'W': 49, 'w': 50, 'X': 51, + 'x': 52, '6': 53, 'Y': 54, 'y': 55, + 'Z': 56, 'z': 57, '7': 58, '8': 59, + '9': 60, '0': 61} + + link_id = input("Please input link ID: ") + for c in link_id: + if c not in field_map.keys(): + raise ValueError("Invalid link ID") + + link_id_converted = 0 + for i in range(len(link_id)): + link_id_converted += field_map[link_id[::-1][i]] * 62 ** i + + print("Converted result is: {}".format(link_id_converted)) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/encode.py b/encode.py new file mode 100644 index 0000000..59dfe25 --- /dev/null +++ b/encode.py @@ -0,0 +1,38 @@ +def main(): + link_id_converted = input("Please input converted result: ") + try: + link_id_converted = int(link_id_converted) + except: + raise ValueError("Invalid converted result") + + field_map = { + 'A': 0, 'a': 1, 'B': 2, 'b': 3, + 'C': 4, 'c': 5, 'D': 6, 'd': 7, + '1': 8, 'E': 9, 'e': 10, 'F': 11, + 'f': 12, 'G': 13, 'g': 14, 'H': 15, + 'h': 16, '2': 17, 'I': 18, 'i': 19, + 'J': 20, 'j': 21, 'K': 22, 'k': 23, + 'L': 24, 'l': 25, '3': 26, 'M': 27, + 'm': 28, 'N': 29, 'n': 30, 'O': 31, + 'o': 32, 'P': 33, 'p': 34, '4': 35, + 'Q': 36, 'q': 37, 'R': 38, 'r': 39, + 'S': 40, 's': 41, 'T': 42, 't': 43, + '5': 44, 'U': 45, 'u': 46, 'V': 47, + 'v': 48, 'W': 49, 'w': 50, 'X': 51, + 'x': 52, '6': 53, 'Y': 54, 'y': 55, + 'Z': 56, 'z': 57, '7': 58, '8': 59, + '9': 60, '0': 61} + field_map = {v:k for k, v in field_map.items()} + + link_id = [] + while link_id_converted > 0: + remainder = link_id_converted % 62 + link_id.append(field_map[remainder]) + link_id_converted = link_id_converted // 62 + + original_link_id = ''.join(link_id[::-1]) + + print("Link ID is: {}".format(original_link_id)) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/main.py b/main.py index c44d47c..962788d 100644 --- a/main.py +++ b/main.py @@ -50,7 +50,7 @@ def route(link_id: str): return redirect("https://www.ghink.net") link_id_converted = 0 for i in range(len(link_id)): - link_id_converted += field_map[link_id[::-1][i]] * 56 ** i + link_id_converted += field_map[link_id[::-1][i]] * 62 ** i try: db.ping() @@ -103,7 +103,7 @@ def add(): link_id_random = ''.join(random.sample(tuple(field_map.keys()), 6)) link_id_converted = 0 for i in range(len(link_id_random)): - link_id_converted += field_map[link_id_random[::-1][i]] * 56 ** i + link_id_converted += field_map[link_id_random[::-1][i]] * 62 ** i # Get Cursor try: db.ping()