Blob


1 -,+[ Read first character and start outer character reading loop
2 -[ Skip forward if character is 0
3 >>++++[>++++++++<-] Set up divisor (32) for division loop
4 (MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero)
5 <+<-[ Set up dividend (x minus 1) and enter division loop
6 >+>+>-[>>>] Increase copy and remainder / reduce divisor / Normal case: skip forward
7 <[[>+<-]>>+>] Special case: move remainder back to divisor and increase quotient
8 <<<<<- Decrement dividend
9 ] End division loop
10 ]>>>[-]+ End skip loop; zero former divisor and reuse space for a flag
11 >--[-[<->+++[-]]]<[ Zero that flag unless quotient was 2 or 3; zero quotient; check flag
12 ++++++++++++<[ If flag then set up divisor (13) for second division loop
13 (MEMORY LAYOUT: zero copy dividend divisor remainder quotient zero zero)
14 >-[>+>>] Reduce divisor; Normal case: increase remainder
15 >[+[<+>-]>+>>] Special case: increase remainder / move it back to divisor / increase quotient
16 <<<<<- Decrease dividend
17 ] End division loop
18 >>[<+>-] Add remainder back to divisor to get a useful 13
19 >[ Skip forward if quotient was 0
20 -[ Decrement quotient and skip forward if quotient was 1
21 -<<[-]>> Zero quotient and divisor if quotient was 2
22 ]<<[<<->>-]>> Zero divisor and subtract 13 from copy if quotient was 1
23 ]<<[<<+>>-] Zero divisor and add 13 to copy if quotient was 0
24 ] End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3)
25 <[-] Clear remainder from first division if second division was skipped
26 <.[-] Output ROT13ed character from copy and clear it
27 <-,+ Read next character
28 ] End character reading loop