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.

  • roberto [any]
    ·
    5 months ago

    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'
    
    
    • TankieTanuki [he/him]
      hexagon
      ·
      edit-2
      5 months ago

      Thank you!

      party-blob gold-communist gold-antifa meow-bounce

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