• How to decode algorithm?

    SapnaVishwas Member

    I try to find how decode algorithm, spend many hours to find it and no idea how to to this.
    There is some decode lines.

    00 00 00 00 00 01 -> 80 00 00 00 00 00
    00 00 00 00 00 02 -> 00 00 00 00 00 01
    00 00 00 00 00 03 -> 3F FF FF FF FF FF
    00 00 00 00 00 04 -> 00 00 00 00 00 02
    00 00 00 00 00 05 -> BF FF FF FF FF FE
    00 00 00 00 00 06 -> 7F FF FF FF FF FE
    00 00 00 00 00 07 -> E0 00 00 00 00 00
    00 00 00 00 00 08 -> 00 00 00 00 00 04
    00 00 00 00 00 09 -> BF FF FF FF FF FD
    00 00 00 00 00 10 -> 00 00 00 00 00 08
    00 00 00 00 00 11 -> 00 00 00 00 00 11
    00 00 00 00 00 12 -> 7F FF FF FF FF FB
    00 00 00 00 00 13 -> 60 00 00 00 00 02
    00 00 00 00 00 14 -> FF FF FF FF FF FA
    00 00 00 00 00 15 -> A0 00 00 00 00 02
    00 00 00 00 00 16 -> C0 00 00 00 00 02
    00 00 00 00 00 17 -> 8F FF FF FF FF FE
    00 00 00 00 00 18 -> FF FF FF FF FF F9
    00 00 00 00 00 19 -> 20 00 00 00 00 03
    00 00 00 00 00 20 -> 00 00 00 00 00 10
    
  • Abhey Member

    Maybe this isn’t as hard?. Decoding algorithm (at least for sampled data) can be defined as simple circular, right bitwise shift. Number of shifted digits, depends of number of ‘1’ in 48-bits digit binary representation. All clear now? No? So let’s make quick example:

    0x15 =
    00000000 00000000 00000000 00000000 00000000 00010101 in 48-bits binary representation.
    How many '1' it had? 3, so we need to shift everything 3 places to the right, now we got:
    10100000 00000000 00000000 00000000 00000000 00000010
    3 is odd Number, right? So we dont need to do anything else, and A00000000002 (hex representation of digit above) is our answer.
    
    When number of '1' in encoded data is even number, final result is negation of result obtained by shifting operation. In above case it will be:
    01011111 11111111 11111111 11111111 11111111 11111101 (but we don't need do that for 0x15)
    

    Decoding algorithm in C++ can be implemented that way:

    __int64 encode(__int64 d)
    {
       int one_cunter = 0;
       __int64 mask = 0;
       __int64 ander = 1;
    
    
       for(int i = 0; i < 48; i++)
       {
          if(d & (ander<> one_cunter);
    
       return one_cunter % 2 ? ret :  ~ret & 0x0000FFFFFFFFFFFF;
    }
    
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
       __int64 data[] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20 };
       for (int i = 0; i < 20; i++)
       {
          std::cout<< std::hex << data[i] << " ->\t"<< std::setfill ('0') << std::setw(12)  << encode(data[i]) << std::endl;
       }
    }
    
Viewing 1 reply thread
  • You must be logged in to reply to this topic.
en_USEnglish