FarCry makes heavy use of UUIDs. I am a fan of UUIDs myself, but in some instances they are a bit long. It seems like there should be a way to make them shorter and still have them hold their value. I had a need for a shorter UUID and set out to find a way to compress a UUID.

It kind of worked. It wont work for my purposes so it was a wash for me, but it was still quite a bit of fun and I figured I might as well get a blog post out of all the work.

My example UUID: ED11C880-FA56-11DD-A604001EC203A3AD

After looking at it for a while, it dawned on me that all the characters are hex values… which means each value can only have 16 values… which means you should be able to fit it into 4 bits. If that’s the case, then (after the 3 dashes are removed), it should be possible to reduce the UUID by 50%.

First I set up a simple table to look up each value. Basically just:

Picture 1-7

Then I wrote a simple loop that grabbed two chars at a time from the UUID, looked up their value in the Hex table, and then set the lower order bits to the first char, and the higher order bits to the second char. This table is an output from the loop:

Picture 2-3

As you can see the 8 bits of output (far right) is the binary representation of the integer index to 2 of the actual Hex values.

It does indeed work, hooray!

Going in reverse, looping over eight bits at a time, breaking them into 4 bits, turning them into integers and then looking up the proper Hex value works equally well (as you would expect)

Picture 3-2

The reason this is a failure for me is that there doesn’t appear to be a way to pass this information in the URL. If you were to just look at this string, it would be gobbledygook since it has high ASCII and non-printable characters. It looks like this actually:

Picture 4

There are only 3 ways I can think of to pass data like this in the url

  1. Hex encode - that results in the exact same string I started out with :-/
  2. URL encoded - makes the output way longer than just the UUID by itself.
  3. base64 - Humorously makes the string the same length as the UUID (MMOeEcKMCMKvZRHDnWpAw6EsMDrDmg==).

So… the whole thing was a “waste of time” (unless you have any suggestions).

It was fun to have my theory work out, but it was quite a let down that it’s completely useless for my needs.