1 def randomart(dgst, header="DIGEST"):
2 """Drunken-bishop algorithm for visualizing random art of the digest
4 augmentation = " .o+=*BOX@%&#/^SE"
5 max_len = len(augmentation) - 1
8 field = [[0 for _ in range(field_y)] for _ in range(field_x)]
14 x += 1 if (byte & 0x1) else -1
15 y += 1 if (byte & 0x2) else -1
16 x = min(max(x, 0), field_x - 1)
17 y = min(max(y, 0), field_y - 1)
18 if field[x][y] < max_len - 2:
21 field[field_x // 2][field_y // 2] = augmentation.index("S")
22 field[x][y] = augmentation.index("E")
23 result = ["+--[%s]%s+" % (header, "-" * (field_x - 2 - 2 - len(header)))]
24 for y in range(field_y):
25 result.append("|%s|" % "".join(
26 [augmentation[min(field[x][y], max_len)] for x in range(field_x)]
28 result.append("+%s+" % ("-" * field_x))