I've been trying to implement the new SIMON block cipher in Ruby as a personal challenge. The spec didn't include a pseudocode version of the decryption but I thought I had it figured out. The code I wrote is located at https://github.com/Rami114/Personal/blob/master/Simon/Simon.rb
I've based this on the spec available at http://eprint.iacr.org/2013/404.pdf
Currently my encryption does not work (at all I'd say) which may be due to code issues or do to math failure on my behalf. Could someone please help me validate if the decryption is correct. Most notably the inversion of the rounds:
# f(x) ((LCS(x,1) & LCS(x,8)) ^ LCS(x,2)) def self.f (x, block_size) ((lcs(x, block_size, 1) & lcs(x, block_size, 8)) ^ lcs(x, block_size, 2)) end def self.round_inv (x, y, k1, k2) x ^= k2 x ^= f(y, N) y ^= k1 y ^= f(x, N) return x, y end
And the decryption function which I won't fully paste here as it's defined in the link above (the whole thing is only 200 lines long total so not a monster to read).
I have a stackoverflow question up at the moment which is specific to the way I'm currently converting strings to bignums and back (to accommodate the circular shift) but I didn't think that would be appropriate to this SE site.
Are there any glaring errors in my implementation? I'm by no means an expert in this.
E: the stackoverflow question I have up for code concerns: https://stackoverflow.com/questions/17785691/string-to-bignum-and-back-again-in-ruby-to-allow-circular-shift