Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
using a block table solution in Clear category for Rotating Grille Cipher by juestr
_rotation90 = [3, 7, 11, 15, 2, 6, 10, 14, 1, 5, 9, 13, 0, 4, 8, 12]
rot90 = lambda idxs: sorted(_rotation90[i] for i in idxs)
range16 = tuple(range(16))
def grille_encrypt(plaintext: str, grille: list[str]) -> str | None:
grilleidxs = [idx for idx, x in enumerate(''.join(grille)) if x == 'X']
if grilleidxs:
blockidxs = grilleidxs + (i:=rot90(grilleidxs)) + (i:=rot90(i)) + rot90(i)
verifier, blocktbl = zip(*sorted(zip(blockidxs, range16)))
if verifier == range16:
return ''.join(plaintext[i+j] for i in range(0, len(plaintext), 16) for j in blocktbl)
Dec. 19, 2021
Comments: