From 1dbb392b74312df6b1e6899943c8395b417ddeaa Mon Sep 17 00:00:00 2001 From: Hash Republic Date: Sat, 5 Oct 2024 08:01:46 +0000 Subject: [PATCH 1/2] added pot2wl.py utils --- src/pot2wl.py | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/pot2wl.py diff --git a/src/pot2wl.py b/src/pot2wl.py new file mode 100644 index 0000000..4d565a5 --- /dev/null +++ b/src/pot2wl.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +# Name........: pot2wl.py +# Author......: Hash Republic +# License.....: MIT + +import sys +import argparse + +def print_progress_bar(iteration, total, length=40): + percent = (iteration / total) * 100 + bar_length = int(length * percent // 100) + bar = '#' * bar_length + '-' * (length - bar_length) + sys.stdout.write(f'\r-> |{bar}| {percent:.2f}% Complete') + sys.stdout.flush() + +def hex_to_string(input): + if input.startswith('$HEX[') and input.endswith(']'): + hex_part = input[5:-1] + try: + decoded_string = bytes.fromhex(hex_part).decode('utf-8') + return decoded_string + except ValueError: + return input + else: + return input + +def keep_after_last_colon(input_string): + last_colon_index = input_string.rfind(':') + if last_colon_index != -1: + return input_string[last_colon_index + 1:].strip() + return input_string.strip() + +def main(): + parser = argparse.ArgumentParser(description="Example program to parse flags.") + parser.add_argument('--input', type=str, required=True, help='Input file name') + parser.add_argument('--output', type=str, help='Output file name') + parser.add_argument('--unhex', action='store_true', help='Unhex the input data') + parser.add_argument('--sort', action='store_true', help='Sort by occurences descending (slower)') + args = parser.parse_args() + + word_count = {} + outfile = None + if args.output: + outfile = open(args.output, 'w') + + with open(args.input, 'r') as infile: + total_lines = sum(1 for _ in infile) + infile.seek(0) + if args.sort: + print("-> Generating dict ...") + print_progress_bar(0, total_lines) + for i, line in enumerate(reversed(list(infile))): + r = keep_after_last_colon(line) + if args.unhex: + r = hex_to_string(r) + if args.sort: + if r in word_count: + word_count[r] += 1 + else: + word_count[r] = 1 + print_progress_bar(i+1 , total_lines) + else: + if outfile is None: + print(r) + else: + outfile.write(r + "\n") + + if args.sort: + print("") + print("-> Sorting dict ...") + sorted_word_count = sorted(word_count.items(), key=lambda item: item[1], reverse=True) + print("-> Complete") + for r, count in sorted_word_count: + if outfile is None: + print(r) + else: + outfile.write(r + "\n") + + if outfile is not None: + outfile.close() + +if __name__ == "__main__": + main() \ No newline at end of file From 04305a99bc53dd8774f86cff60c136499b7d334b Mon Sep 17 00:00:00 2001 From: Hash Republic Date: Wed, 9 Oct 2024 15:31:59 +0000 Subject: [PATCH 2/2] Fixed encoding type --- src/pot2wl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pot2wl.py b/src/pot2wl.py index 4d565a5..001e1cc 100644 --- a/src/pot2wl.py +++ b/src/pot2wl.py @@ -18,7 +18,7 @@ def hex_to_string(input): if input.startswith('$HEX[') and input.endswith(']'): hex_part = input[5:-1] try: - decoded_string = bytes.fromhex(hex_part).decode('utf-8') + decoded_string = bytes.fromhex(hex_part).decode('ISO-8859-1') return decoded_string except ValueError: return input