Shortening a GUID

Viewed 703

We generate a GUID for a document and need to include the GUID in a barcode (Type 29 2D) which is C40 encoded and has the following restrictions.

Can be a max length of 25 characters Can only use UPPER Alphanumerical characters, no special characters.

I had thought of converting to Base64 but that uses special characters.

1 Answers

You could use a base36 encoding.

Given that a UUID is only 16 bytes, it should fit into 25 base36 characters.

To demonstrate, here's a small JavaScript snippet that takes the example UUID from the Wikipedia page (123e4567-e89b-12d3-a456-426614174000) and converts it to base36:

const guid = BigInt('0x123e4567e89b12d3a456426614174000');
const encoded = guid.toString(36).toUpperCase();

console.log("Encoded: " + encoded); // 12VQJRNXK8WHV3I8QI6QGRLZ4
console.log("Length: " + encoded.length); // 25

Related