Skip to content

Latest commit

 

History

History
92 lines (75 loc) · 2.23 KB

README.md

File metadata and controls

92 lines (75 loc) · 2.23 KB

Ook Brainfuck

Ook encoder written in Brainfuck.

A majority of the logic is duplicated so the final Brainfuck is generated by the encode-gen.rb script. There is a sample Brainfuck script in encode.bf.

Generator

ruby ./brainfuck-gen.rb "text to encode"

Draft Notes

# Reserves 5 registers at the start
>>>>>

# Input text
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# Move to the first character
[<]>

[
  # start MATCHING_LOGIC

  # Set the logic registers
  < [-]  # Copy temp
  < [-]  # Copy working value
  < [-]  # Logic A set to 0 intiially and is set to one if partial match
  < [-]+ # Logic B set to 1 initially and is set to zero if no match
  < [-]+ # Unmatched set to 1 initially
  >>>>>

  # Moves value to the previous two registers
  [-<+<+>>]
  # Move value from behind to original cursor
  <[->+<]<

  # Detect the letter m
  ------------------------------------------------------------------------------------------------------------
  [
    <+
    >-
    [
      <<->>
      [-]
    ]
    <
    [
      <
      # If true, we found the character m
      [
        # Clear the registers for printing
        >[-]<[-]
        # Print the same character for now but OOKs should be printed here
        +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
        # Clear the unmatched register
        <
        [-]
        >
        # Break
        [-]
      ]
      >
      # Break
      [-]
    ]
    >
  ]
  # end MATCHING_LOGIC

  # start CONTINUATION_LOGIC
  <<<
  [
    # Unmatched if we enter here
    >>>>>

    # Repeat MATCHING_LOGIC here for remaining characters

    <<<
  ]
  >>>
  # end CONTINUATION_LOGIC

  # Move to next character
  >>>
]

# Print trailing k here