diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-11-17 17:56:09 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-11-17 18:02:27 +0100 |
| commit | 390f6c5360fdc8f49c1ecbd1747a0fb5f5282225 (patch) | |
| tree | d93bd4b8acfa0ce95467cbd2462b2f8a6a389894 /examples/rot13.bf | |
| parent | 285b331ac60d075bba4f721fe412a52576f50539 (diff) | |
| download | bfc-390f6c5360fdc8f49c1ecbd1747a0fb5f5282225.tar.gz bfc-390f6c5360fdc8f49c1ecbd1747a0fb5f5282225.tar.bz2 bfc-390f6c5360fdc8f49c1ecbd1747a0fb5f5282225.zip | |
Added Makefile
Diffstat (limited to 'examples/rot13.bf')
| -rw-r--r-- | examples/rot13.bf | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/rot13.bf b/examples/rot13.bf new file mode 100644 index 0000000..3ce3faf --- /dev/null +++ b/examples/rot13.bf @@ -0,0 +1,28 @@ +-,+[ ; Read first character and start outer character reading loop + -[ ; Skip forward if character is 0 + >>++++[>++++++++<-] ; Set up divisor (32) for division loop + ; (MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero) + <+<-[ ; Set up dividend (x minus 1) and enter division loop + >+>+>-[>>>] ; Increase copy and remainder / reduce divisor / Normal case: skip forward + <[[>+<-]>>+>] ; Special case: move remainder back to divisor and increase quotient + <<<<<- ; Decrement dividend + ] ; End division loop + ]>>>[-]+ ; End skip loop; zero former divisor and reuse space for a flag + >--[-[<->+++[-]]]<[ ; Zero that flag unless quotient was 2 or 3; zero quotient; check flag + ++++++++++++<[ ; If flag then set up divisor (13) for second division loop + ; (MEMORY LAYOUT: zero copy dividend divisor remainder quotient zero zero) + >-[>+>>] ; Reduce divisor; Normal case: increase remainder + >[+[<+>-]>+>>] ; Special case: increase remainder / move it back to divisor / increase quotient + <<<<<- ; Decrease dividend + ] ; End division loop + >>[<+>-] ; Add remainder back to divisor to get a useful 13 + >[ ; Skip forward if quotient was 0 + -[ ; Decrement quotient and skip forward if quotient was 1 + -<<[-]>> ; Zero quotient and divisor if quotient was 2 + ]<<[<<->>-]>> ; Zero divisor and subtract 13 from copy if quotient was 1 + ]<<[<<+>>-] ; Zero divisor and add 13 to copy if quotient was 0 + ] ; End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3) + <[-] ; Clear remainder from first division if second division was skipped + <.[-] ; Output ROT13ed character from copy and clear it + <-,+ ; Read next character +] ; End character reading loop |
