Encrypt:
ffii{{~~__:0a('0'*!.0a('0'*22(!'(~$~_:}-}$-a*}+{{if~~:i:0({}?;__:{}84{}*__({}?\__:{} _{}70{}g_{})_{}?\4__{}8*-_{}+{}80{}g_%4_{}8*{}+\\sl||||||||||||||||||||||||||||9||||||||||||||9||||||||||||||||||||||||||||||||||||||||||||||||||||9
> > >!;7f7-_{}!%_{}!<872-d_{}!&_{}!<[755(7(%~~_{}!<[55(7(_{}!*!*23a(_{}!'_{}!"55(7((~~_{}~~~o__'4'0.{{{o,
Decrypt:
iill~~""bb=3d+*3*-$13d+*3*-55+$*+"'"b=!0!'0d-!.~~li""=l=3+~!B>bb=~!;7~!-bb+~!B_bb=~!#b~!:3~!jb~!,b~!B_7bb~!;-0b~!.~!;3~!jb(7b~!;-~!.__vo < < <
##############################################################################A######################A##############################A$>:i:0b~!$(b~!$?;:50gb~!$)b~!$?^:88+:+(""b~!$?^88+:+b~!$-$-56d+b~!$*b~!$%88+:++""b~!"""rbb*7*31~~~r/
The two programs are offset by 3, and they take input of the form:
<2-digit offset> <text>
The offset must be 2 digits, so an offset of 5 needs to be entered as 05
.
This is a long submission, but nearly all non-filler chars are used by both programs. There's a lot of whitespace that can definitely be golfed out, but I thought the program would be more interesting this way.
This image highlights the chars used by both programs.
Explanation
The main construct that makes this possible is _{} -> b~!
, which allows arbitrary skipping of chars in the decryption program. How?
Encrypt:
_ : Mirror, but is a no-op if the program flow is horizontal
{ : Shift stack left
} : Shift stack right
Decrypt:
b : Push 11 to stack
~ : Pop top of stack
! : Skip the next instruction
All in all, the encryption program does nothing, but the decryption program skips the next instruction. This can then be extended to _{}! -> b~!$
, which allows arbitrary skipping of chars in the encryption program instead.
Aside from this, most of the rest of the program is pushing numbers, performing operations on those numbers then finding ways to pop them. For example, one useful construct is ~~ -> ""
, which pops two values for the encryption program, but pushes nothing in the decryption program.
><>, 149 bytes
Here's the less interesting version, which uses the fact that instructions not passed through are effectively comments in 2D languages.
Encrypt:
i68*:@-a*i@@-+i~v
4:v?)g31:;?(0:i:/8
(?v48*-+03g%48*+\*
_~\of0. .1+1fo/
j*+:zq<6B99A6=qz6g
53Ji?C58/8;?r0?C5:
C?EiJ4r?<EFJ3;EtEg
:tAC5EK8l5tKK86t*i
Decrypt:
^+-~/5"V~^55" ^sk
)/k4}\(&/04|%/^/$-
|4k)-~" %(\y)-~ Q~
TsQd[%#ttt#& &[d$
_~ /of1+7..6+2fo+\
*(?^48*-$-04g%48*/
84:^?)g41:;?(0:i:\
/i68*:@-a*i@@-+i~^
The two programs are offset by 84, and take input the same way as above. The first instruction decides which half of the program to execute, with i
(input) maintaining program flow rightward in the encryption program, and ^
redirecting program flow upward (looping around and coming back from the bottom) in the decryption program.
Explanation
For the relevant half of the encryption program (decryption program is similar):
i read first input digit as char
68*:@-a* subtract 48 (ASCII "0") and multiply by 10, keeping another 48 on the stack
i read second input digit as char
@@-+ subtract 48 and add to 10*(first digit), giving the offset
i~ read in space and discard it
--- LOOP ---
: copy the offset
i: read input char
:0)?; check if less than 0 (i.e. EOF) and terminate if so
:13g)?v check if greater than ~ in cell (1,3) and drop down if so
48*(?v check if less than 32 and drop down if so
48*-+03g%48*+ calculate Caesar shift of the char, fetching 95 from (0,3)
of1+1. repeat loop
of0. repeat loop
Coding tool
This isn't related to the rest of the post above, but I thought I'd post this because I need to use it :P
for(var i=0;i<95;++i){var option=document.createElement("option");option.text=i;document.getElementById("offset").add(option)};function update(m){if(m==1)var code=document.getElementById("in").value;else var code=document.getElementById("out").value;var offset=parseInt(document.getElementById("offset").value);var output="";for(var i=0;i<code.length;i++){var n=code[i].charCodeAt(0);if(n<32||n>127)output+=code[i];else{var c=(n-32+offset*m)%95;output+=String.fromCharCode(c<0?c+95+32:c+32)}}if(m==1)document.getElementById("out").value=output;else document.getElementById("in").value=output};
<html><body><textarea id="in" onkeyup="update(1)" rows=5 style="width:100%"></textarea><textarea id="out" rows=5 style="width:100%" onkeyup="update(-1)"></textarea><select id="offset" onchange="update(1)"></select></body></html>