How do you get from the value on the left to the value on the right?

UUID ?
2126816c-89f5-4aab-842f-65b9f3a39c8b 56qHyeZvHYZitUFukWo5rz
8b9f9c44-6e1b-485b-af00-c8b0e0067d59 ieZJYUFB83oQacsNiQ55Bt
72bd4bd2-9538-43f3-81b2-b8df991a32d8 faLTidGsoG1G1TPLKUFcJh

It’s not hex to base64 or hex to base58. That’s when I gave up and decided to comradesource it.


Context


PeerTube creates two URLs for each video. The original, long one looks like this:

https://tankie.tube/videos/watch/2126816c-89f5-4aab-842f-65b9f3a39c8b

And the sleeker format looks like this:

https://tankie.tube/w/faLTidGsoG1G1TPLKUFcJh

The database only stores the UUID so the shorter ID must be a function of the first.

6 points

It is int to base58. uuidToShort is the function, calling fromUUID from short-uuid.

There are multiple base58 implementations and I think this is the one bitcoin doesn’t use, which might make an online base58 translator get it wrong. short-uuid calls it “flickrBase58.”

This gets the correct answers:

def b58encode(fid):
  CHARS = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
  CHAR_NUM = len(CHARS)
  encoded = ''
  fid = int(fid)

  while fid >= CHAR_NUM:
    div, mod = divmod(fid, CHAR_NUM)
    encoded = CHARS[mod] + encoded
    fid = div
  return CHARS[fid] + encoded

In [2]: b58encode(0x2126816c89f54aab842f65b9f3a39c8b)
Out[2]: '56qHyeZvHYZitUFukWo5rz'

In [3]: b58encode(0x8b9f9c446e1b485baf00c8b0e0067d59)
Out[3]: 'ieZJYUFB83oQacsNiQ55Bt'

In [4]: b58encode(0x72bd4bd2953843f381b2b8df991a32d8)
Out[4]: 'faLTidGsoG1G1TPLKUFcJh'

permalink
report
reply
4 points
*

Thank you!

It looks like the bitcoin implementation has the lowercase letters coming after the uppercase. That explains it. I assumed it was standardized.

permalink
report
parent
reply

chat

!chat@hexbear.net

Create post

Chat is a text only community for casual conversation, please keep shitposting to the absolute minimum. This is intended to be a separate space from c/chapotraphouse or the daily megathread. Chat does this by being a long-form community where topics will remain from day to day unlike the megathread, and it is distinct from c/chapotraphouse in that we ask you to engage in this community in a genuine way. Please keep shitposting, bits, and irony to a minimum.

As with all communities posts need to abide by the code of conduct, additionally moderators will remove any posts or comments deemed to be inappropriate.

Thank you and happy chatting!

Community stats

  • 149

    Monthly active users

  • 3.6K

    Posts

  • 62K

    Comments