Note that there are some explanatory texts on larger screens.

plurals
  1. POPython --- multiplication in GF(2) field
    primarykey
    data
    text
    <p>This function is returning unusual values in the list g. It should return 32774, 65548, 1048768 but instead it's values are more like it's treating the entire binary like a big slinky and just moving the LSB's towards the MSB's instead of actually shifting.</p> <p>Here's the function:</p> <pre><code>def multiply(a,b): #a,b are values like 1101010001.... a = min(a,b); b = max(a,b) g = []; bitsa = "{0:b}".format(a) #returns product of 2 polynomials in gf2 [g.append((b&lt;&lt;i)*int(bit)) for i,bit in enumerate(bitsa)] return reduce(lambda x,y: x+y,g) </code></pre> <p>This is what I'm testing with:</p> <pre><code>x = int(str(100000000000011),2) y = int(str(1000110),2) x1 = int(str(111),2) y1 = int(str(11),2) x2 = int(str(0001),2) y2 = int(str(1111),2) print "multiply: ",multiply(x,y) print "multiply: ",multiply(x1,y1) print "multiply: ",multiply(x2,y2) </code></pre> <p>Only x1,y1 works right now, the others don't. This is the whole equation for the last input:</p> <pre><code> 100000000000011 1000110 --------------------- 100000000000011 100000000000011 100000000000011 --------------------- 100011000000011001010 </code></pre> <p>So as you can see, to get the product, both binaries need to have their indexes checked for 1's and then append based on that. I'm not sure how to fit that part in, and how to do it so it returns the correct value. Trying to understand why x1,y1 works and the others don't.</p> <p>EDIT:</p> <p>I just want it to be clear that J0HN's answer appears to be completely accurate and furthermore he caught an error in the online tool that was referenced. From what it appears now, the built-in's are preferential when working with finite field math in this way. Anyone happening across this should definitely consider showing him some vote love for those keen observation skills-to-pay-the-bills.</p>
    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. This table or related slice is empty.
    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