Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This reminds me of an old trick from base 10 called "casting out the 9s". This was used for checking the result of large sums performed by hand. In this case <code>123 mod 9 = 1 + 2 + 3 mod 9 = 6</code>. </p> <p>This happens because 9 is one less than the base of the digits (10). (Proof omitted ;) )</p> <p>So considering the number in base 16 (Hex). you should be able to do:</p> <pre><code>0xABCE123 mod 0xF = (0xA + 0xB + 0xC + 0xD + 0xE + 0x1 + 0x2 + 0x3 ) mod 0xF = 0x42 mod 0xF = 0x6 </code></pre> <p>Now you'll still need to do some magic to make the additions disappear. But it gives the right answer.</p> <p>UPDATE:</p> <p>Heres a complete implementation in C++. The <code>f</code> lookup table takes pairs of digits to their sum mod 15. (which is the same as the byte mod 15). We then repack these results and reapply on half as much data each round. </p> <pre class="lang-c++ prettyprint-override"><code>#include &lt;iostream&gt; uint8_t f[256]={ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,0,1, 2,3,4,5,6,7,8,9,10,11,12,13,14,0,1,2, 3,4,5,6,7,8,9,10,11,12,13,14,0,1,2,3, 4,5,6,7,8,9,10,11,12,13,14,0,1,2,3,4, 5,6,7,8,9,10,11,12,13,14,0,1,2,3,4,5, 6,7,8,9,10,11,12,13,14,0,1,2,3,4,5,6, 7,8,9,10,11,12,13,14,0,1,2,3,4,5,6,7, 8,9,10,11,12,13,14,0,1,2,3,4,5,6,7,8, 9,10,11,12,13,14,0,1,2,3,4,5,6,7,8,9, 10,11,12,13,14,0,1,2,3,4,5,6,7,8,9,10, 11,12,13,14,0,1,2,3,4,5,6,7,8,9,10,11, 12,13,14,0,1,2,3,4,5,6,7,8,9,10,11,12, 13,14,0,1,2,3,4,5,6,7,8,9,10,11,12,13, 14,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0}; uint64_t mod15( uint64_t in_v ) { uint8_t * in = (uint8_t*)&amp;in_v; // 12 34 56 78 12 34 56 78 =&gt; aa bb cc dd in[0] = f[in[0]] | (f[in[1]]&lt;&lt;4); in[1] = f[in[2]] | (f[in[3]]&lt;&lt;4); in[2] = f[in[4]] | (f[in[5]]&lt;&lt;4); in[3] = f[in[6]] | (f[in[7]]&lt;&lt;4); // aa bb cc dd =&gt; AA BB in[0] = f[in[0]] | (f[in[1]]&lt;&lt;4); in[1] = f[in[2]] | (f[in[3]]&lt;&lt;4); // AA BB =&gt; DD in[0] = f[in[0]] | (f[in[1]]&lt;&lt;4); // DD =&gt; D return f[in[0]]; } int main() { uint64_t x = 12313231; std::cout&lt;&lt; mod15(x)&lt;&lt;" "&lt;&lt; (x%15)&lt;&lt;std::endl; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload