Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you would be equally happy with <code>unpack('B*')</code> with msb first binary numbers (which you could well be if all your processing is circular), then you could also use <code>.unpack('Q&gt;')</code> instead of <code>.unpack('B*')[0].to_i(2)</code> for generating <code>pt</code>:</p> <pre><code>pt = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!@" # Your version (with 'B' == msb first) for comparison: pt_nums = pt.chars.each_slice(N/8).map {|x| x.join.unpack('B*')[0].to_i(2)}.to_a =&gt; [8176115190769218921, 8030025283835160424, 7668342063789995618, 7957105551900562521, 6145530372635706438, 5136437062280042563, 6215616529169527604, 3834312847369707840] # unpack to 64-bit unsigned integers directly pt_nums = pt.unpack('Q&gt;8') =&gt; [8176115190769218921, 8030025283835160424, 7668342063789995618, 7957105551900562521, 6145530372635706438, 5136437062280042563, 6215616529169527604, 3834312847369707840] </code></pre> <p>There are no native 128-bit pack/unpacks to return in the other direction, but you can use <code>Fixnum</code> to solve this too:</p> <pre><code>split128 = 1 &lt;&lt; 64 ct = pt # Just to show round-trip ct.map { |x| [ x / split128, x % split128 ].pack('Q&gt;2') }.join =&gt; "\x00\x00\x00\x00\x00\x00\x00\x00qwertyui . . . " # truncated </code></pre> <p>This avoids a lot of the temporary stages on your code, but at the expense of using a different byte coding - I don't know enough about SIMON to comment whether this is adaptable to your needs.</p>
 

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