Guest User

z340_poc.py

a guest
Feb 12th, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. import numpy as np
  2.  
  3.  
  4. z340_key = dict(
  5.     A=["K", "*", "z", "O", "l"],
  6.     B=["f", "_"],
  7.     C=["p"],
  8.     D=["S", "A", "6"],
  9.     E=["|", "B", "b", "4", "c", "N"],
  10.     F=["F"],
  11.     G=["L"],
  12.     H=["+"],
  13.     I=["H", "k", "<", "P", "y"],
  14.     J=[],
  15.     K=[],
  16.     L=["d", "7", "t", ],
  17.     M=["2"],
  18.     N=[".", "9", ">", "D", "Y"],
  19.     O=["M", "V", "R", "^"],
  20.     P=["8", "j"],
  21.     Q=[],
  22.     R=["E", "Z", "1", "T"],
  23.     S=["U", "&", "J", "-"],
  24.     T=["(", "#", "G", "%", ";", ":"],
  25.     U=["@", "/", "q"],
  26.     V=["5"],
  27.     W=["W", ")"],
  28.     X=[],
  29.     Y=["C", "3", "X"],
  30.     Z=[],
  31. )
  32.  
  33.  
  34. def substitute(key, alias):
  35.     for letter, aliases in key.items():
  36.         if alias in aliases:
  37.             return letter
  38.  
  39.  
  40. def translate_cipher(cipher, key):
  41.     translated = [substitute(alias=c, key=key) or c for c in cipher.flatten()]
  42.     return np.array(translated).reshape(cipher.shape)
  43.  
  44.  
  45. def transpose_cipher(cipher, period):
  46.     x, y = cipher.shape
  47.     transposed = [cipher[(i * period) % x][(i * period) % y] for i in range(x * y)]
  48.     return np.array(transposed).reshape(cipher.shape)
  49.  
  50.  
  51. def print_cipher(cipher):
  52.     for line in cipher:
  53.         print("".join(line))
  54.  
  55.  
  56. def load_z340(van_eyckes_fix=True):
  57.     z340 = r"""
  58.        HER>pl^VPk|1LTG2d
  59.        Np+B(#O%DWY.<*Kf)
  60.        By:cM+UZGW()L#zHJ
  61.        Spp7^l8*V3pO++RK2
  62.        _9M+ztjd|5FP+&4k/
  63.        p8R^FlO-*dCkF>2D(
  64.        #5+Kq%;2UcXGV.zL|
  65.        (G2Jfj#O+_NYz+@L9
  66.        d<M+b+ZR2FBcyA64K
  67.        -zlUV+^J+Op7<FBy-
  68.        U+R/5tE|DYBpbTMKO
  69.        2<clRJ|*5T4M.+&BF
  70.        z69Sy#+N|5FBc(;8R
  71.        lGFN^f524b.cV4t++
  72.        yBX1*:49CE>VUZ5-+
  73.        |c.3zBK(Op^.fMqG2
  74.        RcT+L16C<+FlWB|)L
  75.        ++)WCzWcPOSHT/()p
  76.        |FkdW<7tB_YOB*-Cc
  77.        >MDHNpkSzZO8A|K;+
  78.    """
  79.     lines = [list(y) for y in (x.strip() for x in z340.split("\n")) if y]
  80.     if van_eyckes_fix:
  81.         # yBX1*:49CE>VUZ5-+  -->  yBX+1*:49CE>VUZ5-  (move plus)
  82.         lines[14] = list("yBX+1*:49CE>VUZ5-")
  83.     return np.array(lines)
  84.  
  85.  
  86. print("\n# Z340 - LINES 1-9 - ORIGINAL\n")
  87.  
  88. print_cipher(
  89.     load_z340()[:9],
  90. )
  91.  
  92. print("\n# Z340 - LINES 1-9 - SUBSTITUTED\n")
  93.  
  94. print_cipher(
  95.     translate_cipher(
  96.         load_z340()[:9],
  97.         key=z340_key
  98.     )
  99. )
  100.  
  101. print("\n# Z340 - LINES 1-9 - SUBSTITUTED AND UNTRANSPOSED\n")
  102.  
  103. print_cipher(
  104.     transpose_cipher(
  105.         translate_cipher(
  106.             load_z340()[:9],
  107.             key=z340_key
  108.         ),
  109.         period=19
  110.     )
  111. )
Advertisement
Add Comment
Please, Sign In to add comment