Skip to content

Instantly share code, notes, and snippets.

@sellout
Created April 30, 2014 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sellout/c637e16ab003b17dfda3 to your computer and use it in GitHub Desktop.
Save sellout/c637e16ab003b17dfda3 to your computer and use it in GitHub Desktop.
KSA : ARC4Key n -> Vect 256 (Mod 256)
KSA {n=(n ** p)} key =
fst (runIdentity (runStateT (nextJ (map Prelude.Classes.fromInteger (fromList [0..255])))
(0, 0)))
where
nextJ : Vect 256 (Mod 256) -> State (Mod 256, Mod 256) (Vect 256 (Mod 256))
nextJ S = do
(i, j) <- get
let ind = tightmod (cast i) (cast n) (stillNotZero n p)
let pos = index ind key
let newJ = the (Mod 256) (j + index (cast i) S + pos)
let newS = (swap (cast i) (cast newJ) S)
if i == maxBound
then
return newS
else do
put (i + 1, newJ)
nextJ newS
-- Data.Crypto.Encryption.ARC4.KSA, nextJ is possibly not total due to: Data.Crypto.Encryption.ARC4.case block in Data.Crypto.Encryption.ARC4.KSA, nextJ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment