31 lines
1.1 KiB
Plaintext
31 lines
1.1 KiB
Plaintext
templates chaocipher&{left:,right:,decode:}
|
|
templates permute
|
|
def ctshift: [ $@chaocipher.ct($..last)..., $@chaocipher.ct(1..$-1)...];
|
|
def p1: $ mod 26 + 1;
|
|
def ptshift: [ $@chaocipher.pt($p1..last)..., $@chaocipher.pt(1..$p1-1)...];
|
|
..|@chaocipher: { ct: [ $ctshift(1), $ctshift(3..14)..., $ctshift(2), $ctshift(15..last)...],
|
|
pt: [ $ptshift(1..2)..., $ptshift(4..14)..., $ptshift(3), $ptshift(15..last)...] };
|
|
end permute
|
|
|
|
@: {ct:[ $left... ], pt: [ $right... ], result:[]};
|
|
$... -> #
|
|
'$@.result...;' !
|
|
|
|
when <?($decode <=0>)> do
|
|
def plain: $;
|
|
def index: $@.pt -> \[i](<=$plain> $i!\) -> $(1);
|
|
..|@.result: $@.ct($index);
|
|
$index -> permute -> !VOID
|
|
otherwise
|
|
def cipher: $;
|
|
def index: $@.ct -> \[i](<=$cipher> $i!\) -> $(1);
|
|
..|@.result: $@.pt($index);
|
|
$index -> permute -> !VOID
|
|
end chaocipher
|
|
|
|
'WELLDONEISBETTERTHANWELLSAID' -> chaocipher&{left:'HXUCZVAMDSLKPEFJRIGTWOBNYQ', right:'PTLNBQDEOYSFAVZKGJRIHWXUMC',decode:0} -> '$;
|
|
' -> !OUT::write
|
|
|
|
'OAHQHCNYNXTSZJRRHJBYHQKSOUJY' -> chaocipher&{left:'HXUCZVAMDSLKPEFJRIGTWOBNYQ', right:'PTLNBQDEOYSFAVZKGJRIHWXUMC',decode:1} -> '$;
|
|
' -> !OUT::write
|