Search code examples
node.jsendiannessbase91

NodeJS, basE91, & little endian


How would I got about decoding the string below from basE91 to readable text using NodeJS?

8D7Hh-9D*.n-!DZrG-#DE-$DD-%DC-sl-tl-BEp2m-CE^Ul-DE}CH-EEE-FED-GEC-<l-=l-hE(.K-iEvqS-jEB-kEB-lEB-mEB-Rm-Sm-%E!{Q-&EDgN-(EG:K-)EE-*EE-+EB-xm-ym-GF{}U-HF()Q-IFt%D-JFE-KFB-LFD-[m-]m-mF;JG-nF7]Q-oF2-pFB-qFC-rFB-Wn-Xn-+FD-,FE-.FB- FE-:FD-;FC-2n-3n-

* EDIT *

Using the basE91 table I managed to convert the string above into a hex string

Hex String

5668557210457684246110336890114713568693668683768671151081161086669112501096769948510868691567726969697069687169676010861108104694046751056911811383106696610769661086966109696682109810937693312381386968103784069715875416969426969436966120109121109717012312585727040418173701637687470697570667670689110993109109705974711107055938111170501127066113706711470668711088104370684470694670664770695870685970675011051110

I then fed that into the buffer

var buf = new Buffer(hex, 'hex');
console.log(buf.toString('utf8'));

This gives me:

VhUr►Ev?$a►3h?◄G‼V??f??v?q§►?▬►?f?↕P►?v?Hhi↕Vw&???♠??▬?va►?♦i@Fu►V?↑◄81♠if►v?if►??h!    ?►??1#?8ih►7?♠?§?T▬??&??6?a ►?!►?↨☺#↕XW'♦♦↑↨7☺▬7htpiupfvph?►?1 ►?♣?G◄►p    U??◄↨♣☺↕pf◄7♠q¶pf??►CphDpiFpfGpiXphYpgP◄♣◄►

How do I get that into something I can use? I'm suspecting it's a JSON object...


Solution

  • You have two very separate problems which are getting conflated in this discussion.

    How can decode basE91 using Javascript/NodeJS/CommnJS?

    This is what your question appears to be at a glance and you've gotten various responses in this vein. The answer appears to be: There isn't an existing solution, but basE91 is small and simple enough that you should be able to port it to JS without too much trouble.

    Your second less explicit question appears to be:

    How can I reverse-engineer Lord of Ultima's game server communication protocol?

    You mentioned that your "basE91 LE" string came from an MMO game server, and this forum posting about Lord of Ultima is pretty much the only other hit for "basE91 little endian". (Plus it looks like you posted there a few days ago.) As variously noted, the data you posted is not plain vanilla basE91. BasE91 has a clearly defined set of characters used and '-' and '' (space) are not among them, but both appear in your data. You mentioned in comments that you thought '-' was being used as a separator, and it'd be easier to answer this second question if more information like that was provided up front.

    Some notes on this question:

    • BasE91 uses a standard encoding table. If you were making a making an online game and wanted to obfuscate your traffic a bit, it'd be trivial to use a different or scrambled table. That would account for characters that aren't legal basE91 appearing in your data. Plus, this post from that forum has what looks to be exactly that: a different de/encoding table. Have you tried using that table to decode part of your data by hand and see if it makes sense?

    • You request conversion to "readable text", but basE91 is used for transmitting binary data so it's not clear why one would use it for plain text. Even assuming that it is encoding text, there are various common ways to encode plain text and the decoded data doesn't appear to be doing so. More likely, the data is actual binary data and, in a very real sense, basE91 is the textual representation. Without more information about the output you're expecting, it's hard to know how you wanted it translated to text. This is the basE91 encoding of a 1 pixel transparent gif:

      JaQGWo*HBtAARDBtB"B"B"S|QtAAAA$M)Bc4v(#AsAAABtAACABtlBLHBtd
      

      Can that be converted to readable text? You mention that you think it's JSON, can you give us some hints about why you think that? (And again, why use a binary encoder for plain text?)

    • Working from the same forum post, it sounds like you're working with a series of 5-bit coordinates, so maybe those numbers are what you're looking for? However, there's still more to the puzzle because those basE91 groups encode different size numbers. To wit (warning wall of inscrutable text):

      echo '8D7Hh-9D*.n-!DZrG-#DE-$DD-%DC-sl-tl-BEp2m-CE^Ul-DE}CH-EEE-FED-GEC-<l-=l-hE(.K-iEvqS-jEB-kEB-lEB-mEB-Rm-Sm-%E!{Q-&EDgN-(EG:K-)EE-*EE-+EB-xm-ym-GF{}U-HF()Q-IFt%D-JFE-KFB-LFD-[m-]m-mF;JG-nF7]Q-oF2-pFB-qFC-rFB-Wn-Xn-+FD-,FE-.FB- FE-:FD-;FC-2n-3n-' \
      | while IFS='' read -d - a; do echo -n "'$a' => "; echo -n "$a" \
      | ./base91 -d | hexdump | head -1 | cut -d ' ' -f 2-; done
      # head and cut are easier that understanding hexdump's formatting system
      '8D7Hh' => 4d 01 57 84                                    
      '9D*.n' => 4e a1 3b 9f                                    
      '!DZrG' => 4f 41 ec 19                                    
      '#DE' => 50 81                                          
      '$DD' => 51 61                                          
      '%DC' => 52 41                                          
      'sl' => 53                                             
      'tl' => 54                                             
      'BEp2m' => 6d 61 6b 9a                                    
      'CE^Ul' => 6e e1 ed 94                                    
      'DE}CH' => 6f c1 21 1c                                    
      'EEE' => 70 81                                          
      'FED' => 71 61                                          
      'GEC' => 72 41                                          
      '<l' => 73                                             
      '=l' => 74                                             
      'hE(.K' => 8d 61 3b 2b                                    
      'iEvqS' => 8e a1 e3 49                                    
      'jEB' => 8f 21                                          
      'kEB' => 90 21                                          
      'lEB' => 91 21                                          
      'mEB' => 92 21                                          
      'Rm' => 93                                             
      'Sm' => 94                                             
      '%E!{Q' => ad 01 da 43                                    
      '&EDgN' => ae 61 6c 35                                    
      '(EG:K' => af 81 4a 2b                                    
      ')EE' => b0 81                                          
      '*EE' => b1 81                                          
      '+EB' => b2 21                                          
      'xm' => b3                                             
      'ym' => b4                                             
      'GF{}U' => cd c1 f3 53                                    
      'HF()Q' => ce e1 0d 43                                    
      'IFt%D' => cf 01 e9 0e                                    
      'JFE' => d0 81                                          
      'KFB' => d1 21                                          
      'LFD' => d2 61                                          
      '[m' => d3                                             
      ']m' => d4                                             
      'mF;JG' => ed c1 6f 18                                    
      'nF7]Q' => ee 21 ac 43                                    
      'oF2' => ef c1                                          
      'pFB' => f0 21                                          
      'qFC' => f1 41                                          
      'rFB' => f2 21                                          
      'Wn' => f3                                             
      'Xn' => f4                                             
      '+FD' => 0d 62                                          
      ',FE' => 0e 82                                          
      '.FB' => 0f 22                                          
      ' FE' => 71                                             
      ':FD' => 11 62                                          
      ';FC' => 12 42                                          
      '2n' => 13                                             
      '3n' => 14           
      

      There's certainly a pattern there, and even look little-endian if you squint right. But they don't mean anything to me, do they look sensible to you?