# The “foo” encoding

Introducing the mysterious foo encoding... based on the common computer programming template variables foo, bar, and baz. This encoding is truly unknown, as a simple sentence of characters returns an unreadable mess of foos and bars and bazes.

Let's say I input the following into my personal encoder: Noodle pie is delicious.

The program spits out the following, which is "foo-encoded":

baz-foo-baz-br- bar-baz-fo-bar- bar-baz-foo-foo- bar-foo-bar-baz- bar-foo-fo-baz- bar-fo-foo-baz- bar-foo-fo-baz- bar-foo-baz-fo- bar-fo-baz-foo- bar-fo-baz-fo- baz-fo-fo-bz- bar-baz-fo-bar- bar-foo-fo-baz- baz-fo-fo-bz- bar-fo-baz-foo- bar-foo-fo-baz- bar-baz-fo-fo- baz-fo-fo-bz- bar-fo-baz-foo- bar-foo-baz-fo- bar-fo-baz-fo- bar-foo-bar-baz- bar-foo-bar-baz- baz-fo-bar-br-


So how does this mysterious encoding work? That's for you to figure out!

EXTRA NOTE: The encoded messages may contain the following phrases: foo, bar, baz, fo, br, and bz. No, they are not mistakes, they are meant to be there.

HINT:

EXTRA CHALLENGE: Create an encoder/decoder for the foo encoding.

# NOTE: THIS PUZZLE HAS BEEN SOLVED.

The newer versions of the encoding contain absolutely no dashes (so an example string would be barfobzbaz instead of bar-fo-bz-baz-. Also, the encoding has been renamed "FBZ" instead of the "foo" encoding.

View benji2240's solution here. I figured I would release some more resources, since the puzzle is solved:

• The project on repl.it. Allows encoding a string and decodes the string that it developed. Written in Python.

• A tutorial showing each step of the encoding process.

• A website that encodes/decodes as you type, using an encoder/decoder written in JavaScript.

• Welcome to Puzzling.SE! This looks like a fun puzzle. I see you already have a couple of badges, good for you. You can get another easy one by taking the tour. Is your fourth term br supposed to be a bar? same with 7th term fo should be a foo? – Chowzen Oct 25 '18 at 22:40
• @Chowzen The program utilizes the keywords foo, bar, baz, fo, br, and bz. I will edit accordingly. – connectyourcharger Oct 25 '18 at 22:42
• @connectyourcharger Could you double-check the sixth group? It's not that I'm confident it's wrong or anything, but it surprises me a bit. – Gareth McCaughan Oct 26 '18 at 3:23
• @GarethMcCaughan Nope, I've triple-checked the encoding and that final string is definitely correct. – connectyourcharger Oct 26 '18 at 10:01
• OK! Thanks, and sorry for doubting you. – Gareth McCaughan Oct 26 '18 at 11:18

The string is reversed, and then each character (including punctuation) is translated to a 4-tuple of {foo, bar, baz, fo, br, bz}.

We know this because

The number of characters is the same as the number of 4-tuples. Frequency analysis shows that i is bar-foo-fo-baz. A little educated guessing on the other recurring characters shows the reversal pretty clearly, which confirms the 1:1 substitution.

Now that we know that,

We know the encoding for each letter:
. -> baz-foo-baz-br-
[space] -> baz-fo-fo-bz-
N -> baz-fo-bar-br-
c -> bar-fo-foo-baz-
d -> bar-fo-baz-fo-
e -> bar-fo-baz-foo-
i -> bar-foo-fo-baz-
l -> bar-foo-baz-fo-
o -> bar-foo-bar-baz-
p -> bar-baz-fo-fo-
s -> bar-baz-fo-bar-
u -> bar-baz-foo-foo-

However,

This is not the obvious choice of a base-6 encoding of ASCII values. In fact, I doubt it's base 6 at all: We have the values for both o and u, which you would expect to be congruent mod 6 and therefore end in the same digit. However, o ends in baz- and u ends in foo-! If it is base 6, some additional transformation is being applied.

It is interesting that

None of that relates the clue, as far as I can tell. And the symbol bz is used only once (in the example string), for the space character.

Edit:

It almost seems like, since the characters encode to 4-tuples, and 4 symbols are much more commonly used than the other 2, that we should translate each symbol into a bit pair. However, this looks like another dead end. For example, [00, 01, 10, 11] => [fo, bar, foo, baz] works for l and p, but is only "close" for the rest (and doesn't explain how br and bz might be used). I don't know where else to go, though, especially considering the hint (Sirius is a binary star).

Edit 2: Solved it! The key is

Different symbols can represent different numbers of bits:

[00, 01, 10, 11, 0, 1] => [fo, foo, br, bar, bz, baz]

This leads to a complication where a single bitstring may represented in multiple ways. One resolution to this is to apply substitutions in a priority order. For example, 11 could be baz-baz-, but bar- is preferred. The above is an example of an ordering that produces the same output as OP for the example string.

I have written an encoder and a decoder in Ruby.

• That's exactly as far as I got and now just looking for some other kind of encoding that would translate. Nothing so far. – MetaZen Oct 26 '18 at 1:24
• I have to say, I'm impressed, but unfortunately, you didn't get the correct answer. Keep trying, but don't over think it! It's actually quite simple once you figure it out. – connectyourcharger Oct 26 '18 at 9:59
• To add on, you are correct that it is not base 6. But if you really use some of the keywords in the hint, you may be able to pull out a computer a related word that can help you... – connectyourcharger Oct 26 '18 at 10:04
• Once you have found the encoding for each letter, isn't it over? What are you going for? – Wais Kamal Oct 27 '18 at 18:12
• @WaisKamal, we have the encoding for each letter of the example, but this is tagged as a "computer-puzzle", so we are still looking for the underlying logic. Ideally, we'll be able to encode/decode any string. – benj2240 Oct 29 '18 at 19:57

I also figured out the @benj2240 part (though I wouldn't have written it up so nicely!). Here's something else that I have observed. Again, not a complete answer. If you imagine that c,d,e are consecutively encoded in base-$$n$$, then we have the following:

c -> bar-fo-foo-baz-
d -> bar-fo-baz-fo-
e -> bar-fo-baz-foo-

Looking at the units column, baz would be $$n-1$$ (about to roll over), fo would be 1, foo would be 2. Looking at the $$n$$s column, baz is foo+1. So we have $$n=3$$, ie ternary numbers (and we ignore bar and bz and br for now).

Now, unfortunately, this doesn't quite work when you roll it out to all the lowercase letters, because there's a couple of ternary numbers that are repeated. But interestingly, it almost works, and the repeated numbers have bar in them. Here's how it works:

3 a bar-fo -foo-fo -
4 b bar-fo -foo-foo-
5 c bar-fo -foo-baz- correct
6 d bar-fo -baz-fo - correct
7 e bar-fo -baz-foo- correct
8 f bar-fo -baz-baz-
9 g bar-foo-fo -fo -
10 h bar-foo-fo -foo-
11 i bar-foo-fo -baz- correct
12 j bar-foo-foo-fo -
13 k bar-foo-foo-foo-
14 l bar-foo-foo-baz- one off
15 m bar-foo-baz-fo -
16 n bar-foo-baz-foo-
17 o bar-foo-baz-baz- correct except for bar<->baz
18 p bar-baz-fo -fo - correct
19 q bar-baz-fo -foo-
20 r bar-baz-fo -baz-
21 s bar-baz-foo-fo - one off and bar<->baz
22 t bar-baz-foo-foo-
23 u bar-baz-foo-baz- one off
24 v bar-baz-baz-fo -
25 w bar-baz-baz-foo-
26 x bar-baz-baz-baz-
27 y bar-fo -fo -fo -
28 z bar-fo -fo -foo-

Unfortunately, this coding is not correct. However, it is within one line of being correct in all cases, apart from a substitution of bar for baz.

So, somehow the bar is shifting things off by one every now and then.

Hopefully this helps someone else. I'm pretty stumped...

• Wow, this is, again, extremely impressive. This work is amazing! But unfortunately, I think you're overthinking it a bit... think binary. – connectyourcharger Oct 27 '18 at 0:12
• I would say this is underthinking it. I do not think your method is going to be "simpler" in any meaningful sense. – Dr Xorile Oct 29 '18 at 16:27
• Actually, I do think you are overthinking it, and I only say that because when I developed this, I didn't even come close to the level of complexity you are demonstrating here. I'm going to post the answer in a couple days, but I encourage you to keep trying to decipher the code. That being said, I want to commend you on your work so far, you've done a great job and you are starting to get close! – connectyourcharger Oct 29 '18 at 21:19
• Just so you are aware, this puzzle was solved by benji2240. – connectyourcharger Oct 30 '18 at 11:02
• Nice one. I got some ideas in that direction, but couldn't quite figure it out. – Dr Xorile Oct 30 '18 at 17:22