SHARE
TWEET

Caesar (naked)

a guest Mar 25th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. !:
  2. |=  [msg=tape key=@ud]
  3. =+  ^=  caesar
  4.     |%
  5.     ++  alpha  "abcdefghijklmnopqrstuvwxyz"
  6.     ++  shift
  7.       |=  [message=tape key=@ud]
  8.       (operate message key (encoder key))
  9.     ++  unshift
  10.       |=  [message=tape key=@ud]
  11.       (operate message key (decoder key))
  12.     ++  operate
  13.       |=  [message=tape key=@ud encoder=(map @t @t)]
  14.       ^-  tape
  15.       %+  turn  message
  16.       |=  a=@t
  17.       (~(got by encoder) a)
  18.     ++  encoder
  19.       |=  [key=@ud]
  20.       =/  keytape=tape  (rott alpha key)
  21.       (coder alpha keytape)
  22.     ++  decoder
  23.       |=  [key=@ud]
  24.       =/  keytape=tape  (rott alpha key)
  25.       (coder keytape alpha)
  26.     ++  coder
  27.       |=  [a=tape b=tape]
  28.       (~(put by (zipper a b)) ' ' ' ')
  29.     ++  zipper
  30.       |=  [a=tape b=tape]
  31.       ^-  (map @t @t)
  32.       =|  chart=(map @t @t)
  33.       ?.  =((lent a) (lent b))
  34.         ~|  %uneven-lengths  !!
  35.       |-
  36.       ?:  |(?=(~ a) ?=(~ b))
  37.           chart
  38.       $(chart (~(put by chart) i.a i.b), a t.a, b t.b)
  39.     ++  rott
  40.       |=  [m=tape n=@ud]
  41.       =/  length=@ud  (lent m)
  42.       =+  s=(trim (mod n length) m)
  43.       (weld q.s p.s)
  44.     --
  45. =.  msg  (cass msg)
  46. :-  (shift.caesar msg key)
  47. (unshift.caesar msg key)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top