Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- z340_key = dict(
- A=["K", "*", "z", "O", "l"],
- B=["f", "_"],
- C=["p"],
- D=["S", "A", "6"],
- E=["|", "B", "b", "4", "c", "N"],
- F=["F"],
- G=["L"],
- H=["+"],
- I=["H", "k", "<", "P", "y"],
- J=[],
- K=[],
- L=["d", "7", "t", ],
- M=["2"],
- N=[".", "9", ">", "D", "Y"],
- O=["M", "V", "R", "^"],
- P=["8", "j"],
- Q=[],
- R=["E", "Z", "1", "T"],
- S=["U", "&", "J", "-"],
- T=["(", "#", "G", "%", ";", ":"],
- U=["@", "/", "q"],
- V=["5"],
- W=["W", ")"],
- X=[],
- Y=["C", "3", "X"],
- Z=[],
- )
- def substitute(key, alias):
- for letter, aliases in key.items():
- if alias in aliases:
- return letter
- def translate_cipher(cipher, key):
- translated = [substitute(alias=c, key=key) or c for c in cipher.flatten()]
- return np.array(translated).reshape(cipher.shape)
- def transpose_cipher(cipher, period):
- x, y = cipher.shape
- transposed = [cipher[(i * period) % x][(i * period) % y] for i in range(x * y)]
- return np.array(transposed).reshape(cipher.shape)
- def print_cipher(cipher):
- for line in cipher:
- print("".join(line))
- def load_z340(van_eyckes_fix=True):
- z340 = r"""
- HER>pl^VPk|1LTG2d
- Np+B(#O%DWY.<*Kf)
- By:cM+UZGW()L#zHJ
- Spp7^l8*V3pO++RK2
- _9M+ztjd|5FP+&4k/
- p8R^FlO-*dCkF>2D(
- #5+Kq%;2UcXGV.zL|
- (G2Jfj#O+_NYz+@L9
- d<M+b+ZR2FBcyA64K
- -zlUV+^J+Op7<FBy-
- U+R/5tE|DYBpbTMKO
- 2<clRJ|*5T4M.+&BF
- z69Sy#+N|5FBc(;8R
- lGFN^f524b.cV4t++
- yBX1*:49CE>VUZ5-+
- |c.3zBK(Op^.fMqG2
- RcT+L16C<+FlWB|)L
- ++)WCzWcPOSHT/()p
- |FkdW<7tB_YOB*-Cc
- >MDHNpkSzZO8A|K;+
- """
- lines = [list(y) for y in (x.strip() for x in z340.split("\n")) if y]
- if van_eyckes_fix:
- # yBX1*:49CE>VUZ5-+ --> yBX+1*:49CE>VUZ5- (move plus)
- lines[14] = list("yBX+1*:49CE>VUZ5-")
- return np.array(lines)
- print("\n# Z340 - LINES 1-9 - ORIGINAL\n")
- print_cipher(
- load_z340()[:9],
- )
- print("\n# Z340 - LINES 1-9 - SUBSTITUTED\n")
- print_cipher(
- translate_cipher(
- load_z340()[:9],
- key=z340_key
- )
- )
- print("\n# Z340 - LINES 1-9 - SUBSTITUTED AND UNTRANSPOSED\n")
- print_cipher(
- transpose_cipher(
- translate_cipher(
- load_z340()[:9],
- key=z340_key
- ),
- period=19
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment