import hashlib def drunken_bishop_ascii(file_path): # 1. Generate the SHA-256 hash of the file sha256 = hashlib.sha256() try: with open(file_path, "rb") as f: while chunk := f.read(4096): sha256.update(chunk) except FileNotFoundError: print("File not found.") return hash_bytes = sha256.digest() # 2. Set up the grid grid_size = 20 grid = [[" " for _ in range(grid_size)] for _ in range(grid_size)] # Start the bishop in the center curr_x = grid_size // 2 curr_y = grid_size // 2 grid[curr_y][curr_x] = "@" # Start point # 3. Define the 4 diagonal movements of a bishop # 0: Up-Left, 1: Up-Right, 2: Down-Left, 3: Down-Right directions = [ (-1, -1), (1, -1), (-1, 1), (1, 1) ] # 4. Move the bishop based on the hash bytes for byte in hash_bytes: # Use modulo 4 to pick one of the four diagonal directions move_index = byte % 4 dx, dy = directions[move_index] # Update position curr_x += dx curr_y += dy # Handle boundaries: Wrap around the edges (Toroidal grid) curr_x = curr_x % grid_size curr_y = curr_y % grid_size # Mark the path with a character # If the bishop visits the same spot twice, it becomes a denser character if grid[curr_y][curr_x] == " ": grid[curr_y][curr_x] = "." elif grid[curr_y][curr_x] == ".": grid[curr_y][curr_x] = "x" else: grid[curr_y][curr_x] = "#" # 5. Print the result print(f"\nDrunken Bishop Fingerprint: {file_path}") print("+" + "-" * grid_size + "+") for row in grid: print(f"|{''.join(row)}|") print("+" + "-" * grid_size + "+") # Usage: Replace 'your_file.txt' with your actual filename drunken_bishop_ascii("/tmp/toto")