37 lines
984 B
Text
37 lines
984 B
Text
{def rot13
|
|
|
|
{def rot13.alphabet {A.split
|
|
abcdefghijklomnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXZ_.}}
|
|
|
|
{def rot13.delta
|
|
{lambda {:i :a}
|
|
{A.get {% {+ {A.in? {A.get :i :a} {rot13.alphabet}}
|
|
32} 64} {rot13.alphabet}}}}
|
|
{def rot13.r
|
|
{lambda {:a :b :n :i}
|
|
{if {> :i :n}
|
|
then :b
|
|
else {rot13.r :a
|
|
{A.set! :i {rot13.delta :i :a} :b}
|
|
:n {+ :i 1}} }}}
|
|
|
|
{lambda {:txt}
|
|
{let { {:t {S.replace \s by _ in :txt}} }
|
|
{S.replace _ by space in
|
|
{A.join {rot13.r {A.split :t}
|
|
{A.new}
|
|
{- {W.length :t} 1}
|
|
0 }}}}}}
|
|
-> rot13
|
|
|
|
1) encoding:
|
|
|
|
{rot13 abcdefghijklomnopqrstuvwxyz
|
|
0123456789
|
|
ABCDEFGHIJKLMNOPQRSTUVWXZ.}
|
|
-> 56789ABCDEFGKIJKLMNOPQRSTUV3WXZ .abcde3fghijklomnopqrstuvwxyz0124
|
|
|
|
2) decoding:
|
|
|
|
{rot13 56789ABCDEFGKIJKLMNOPQRSTUV3WXZ .abcde3fghijklomnopqrstuvwxyz0124}
|
|
-> abcdefghijklomnopqrstuvwxyz 0123456789 ABCDEFGKIJKLMNOPQRSTUVWXZ.
|