Last active
August 29, 2015 14:06
-
-
Save sordina/eeaf09417ca5c430a4cf to your computer and use it in GitHub Desktop.
Adding xorish operations to Data.Bits.Lens
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://en.wikipedia.org/wiki/Rijndael_S-box | |
affineX' :: Word8 -> Word8 -> Word8 | |
affineX' c b = b &~ forM_ [0..7] twiddleBits | |
where | |
twiddleBits :: Int -> StateT Word8 Identity () | |
twiddleBits j = do | |
bitAt j .= f b 4 | |
bitAt j .^|.= f b 5 | |
bitAt j .^|.= f b 6 | |
bitAt j .^|.= f b 7 | |
bitAt j .^|.= f c 0 | |
where | |
f n o = n ^. bitAt (mod (o + j) 8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment