diff --git a/examples/hash_cracker_ray_ready.py b/examples/hash_cracker_ray_ready.py index 7e5f5fd4..fdd1fc6d 100644 --- a/examples/hash_cracker_ray_ready.py +++ b/examples/hash_cracker_ray_ready.py @@ -1,8 +1,8 @@ import argparse -from datetime import datetime import itertools -from typing import Optional +from datetime import datetime from hashlib import sha256 +from typing import Optional # `test`: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 # `foo`: 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae @@ -11,20 +11,25 @@ # `x`: 2d711642b726b04401627ca9fbac32f5c8530fb1903cc4db02258717921a4881 # the character table that we want to use to construct possible phrases -CHARS = [chr(c) for c in itertools.chain( - range(ord("a"), ord("z") + 1), - range(ord("A"), ord("Z") + 1), - range(ord("0"), ord("9") + 1), - range(ord(" "), ord("/") + 1), - range(ord(":"), ord("@") + 1), - range(ord("["), ord("`") + 1), - range(ord("{"), ord("~") + 1), -)] +CHARS = [ + chr(c) + for c in itertools.chain( + range(ord("a"), ord("z") + 1), + range(ord("A"), ord("Z") + 1), + range(ord("0"), ord("9") + 1), + range(ord(" "), ord("/") + 1), + range(ord(":"), ord("@") + 1), + range(ord("["), ord("`") + 1), + range(ord("{"), ord("~") + 1), + ) +] start_time = datetime.now() parser = argparse.ArgumentParser() -parser.add_argument("-l", "--length", type=int, default=3, help="brute force length, default: %(default)s") +parser.add_argument( + "-l", "--length", type=int, default=3, help="brute force length, default: %(default)s" +) parser.add_argument("hash", type=str) args = parser.parse_args() @@ -44,12 +49,12 @@ def str_to_int(value: str) -> int: base = len(CHARS) + 1 intval = 0 for position, digit in zip(itertools.count(), [CHARS.index(v) + 1 for v in reversed(value)]): - intval += digit * base ** position + intval += digit * base**position return intval -def int_to_str(intval: int, round_nulls = False) -> Optional[str]: +def int_to_str(intval: int, round_nulls=False) -> Optional[str]: """ Convert an integer value back to the equivalent string. @@ -97,5 +102,5 @@ def brute_force_range(start_string: str, end_string: str): print( f"finished in {datetime.now() - start_time},", - f"match found: {result}" if result else f"match not found" + f"match found: {result}" if result else f"match not found", ) diff --git a/examples/hash_cracker_without_ray.py b/examples/hash_cracker_without_ray.py index 1f049e7e..089add85 100644 --- a/examples/hash_cracker_without_ray.py +++ b/examples/hash_cracker_without_ray.py @@ -1,7 +1,7 @@ import argparse from datetime import datetime -from itertools import chain from hashlib import sha256 +from itertools import chain # `test`: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 # `foo`: 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae @@ -9,21 +9,30 @@ # `be`: 46599c5bb5c33101f80cea8438e2228085513dbbb19b2f5ce97bd68494d3344d # `x`: 2d711642b726b04401627ca9fbac32f5c8530fb1903cc4db02258717921a4881 -CHARS = [chr(c) for c in chain( - range(ord("a"), ord("z") + 1), - range(ord("A"), ord("Z") + 1), - range(ord("0"), ord("9") + 1), - range(ord(" "), ord("/") + 1), - range(ord(":"), ord("@") + 1), - range(ord("["), ord("`") + 1), - range(ord("{"), ord("~") + 1), -)] +CHARS = [ + chr(c) + for c in chain( + range(ord("a"), ord("z") + 1), + range(ord("A"), ord("Z") + 1), + range(ord("0"), ord("9") + 1), + range(ord(" "), ord("/") + 1), + range(ord(":"), ord("@") + 1), + range(ord("["), ord("`") + 1), + range(ord("{"), ord("~") + 1), + ) +] start_time = datetime.now() parser = argparse.ArgumentParser() parser.add_argument("-w", "--words", type=str, help="dictionary file") -parser.add_argument("-l", "--length", type=int, default=0, help="brute force length (if the `words` dictionary is not provided), default: %(default)s") +parser.add_argument( + "-l", + "--length", + type=int, + default=0, + help="brute force length (if the `words` dictionary is not provided), default: %(default)s", +) parser.add_argument("hash", type=str) args = parser.parse_args() @@ -35,7 +44,6 @@ def word_file(words_file: str): def brute_force(max_len: int): - def brute_force_len(length: int): for char in CHARS: if length <= 1: @@ -62,4 +70,7 @@ def brute_force_len(length: int): result = word.decode("utf-8") break -print(f"finished in {datetime.now() - start_time},", f"match found: {result}" if result else f"match not found") +print( + f"finished in {datetime.now() - start_time},", + f"match found: {result}" if result else f"match not found", +) diff --git a/examples/mandelbrot_image.py b/examples/mandelbrot_image.py index 5493231c..431d86ee 100644 --- a/examples/mandelbrot_image.py +++ b/examples/mandelbrot_image.py @@ -1,10 +1,10 @@ import argparse -from datetime import datetime, timezone import math -from typing import Tuple, NamedTuple +from datetime import datetime, timezone +from typing import NamedTuple, Tuple -from PIL import Image import ray +from PIL import Image ZOOM_BASE = 2.0 @@ -32,7 +32,6 @@ def mandel(x0, y0, max_iter): return draw_pixel(i / max_iter) - def calculate_mandel( tgt_range_x: Tuple[int, int], tgt_range_y: Tuple[int, int], @@ -66,7 +65,7 @@ def draw_mandelbrot( y_range: Tuple[float, float], max_iter: int, num_chunks: int = 1, - use_ray: bool=True, + use_ray: bool = True, ): chunks = list() @@ -130,7 +129,8 @@ def draw_mandelbrot( def argument_parser(): parser = argparse.ArgumentParser("mandelbrot on ray") parser.add_argument( - "-s", "--size", + "-s", + "--size", nargs=2, metavar=("X", "Y"), help="size of the output image, default=%(default)s", @@ -138,27 +138,31 @@ def argument_parser(): default=(500, 500), ) parser.add_argument( - "-c", "--center", + "-c", + "--center", nargs=2, metavar=("X", "Y"), help="center of the drawn region, default=%(default)s", type=float, - default=(-.743643135, .131825963), + default=(-0.743643135, 0.131825963), ) parser.add_argument( - "-z", "--zoom", + "-z", + "--zoom", help="magnification of the drawn region, default=%(default)s", type=float, - default=200000 + default=200000, ) parser.add_argument( - "-i", "--max-iterations", + "-i", + "--max-iterations", help="maximum number of iterations to perform per pixel, default=%(default)s", type=int, default=500, ) parser.add_argument( - "-n", "--num-chunks", + "-n", + "--num-chunks", help="number of chunks to divide output into, default=%(default)s", type=int, default=16, @@ -168,14 +172,15 @@ def argument_parser(): help="number of CPUs for ray to use", type=int, ) - parser.add_argument("-r", "--use-ray", action='store_true', help="use ray") + parser.add_argument("-r", "--use-ray", action="store_true", help="use ray") parser.add_argument( - "-R", "--no-use-ray", dest='use_ray', action='store_false', help="don't use ray" + "-R", "--no-use-ray", dest="use_ray", action="store_false", help="don't use ray" ) parser.set_defaults(use_ray=True) return parser + #### @@ -196,7 +201,7 @@ def argument_parser(): x_range=(args.center[0] - ZOOM_BASE / args.zoom, args.center[0] + ZOOM_BASE / args.zoom), y_range=( args.center[1] - ZOOM_BASE / (args.zoom * aspect_ratio), - args.center[1] + ZOOM_BASE / (args.zoom * aspect_ratio) + args.center[1] + ZOOM_BASE / (args.zoom * aspect_ratio), ), max_iter=args.max_iterations, num_chunks=args.num_chunks,