Skip to content

Instantly share code, notes, and snippets.

@sellout
Created April 27, 2014 22:18
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/11356985 to your computer and use it in GitHub Desktop.
Save sellout/11356985 to your computer and use it in GitHub Desktop.
KeySize : Type
KeySize = Fin 256 -- should actually be [1-256], not [0-256]
public
ARC4Key : KeySize -> Type
ARC4Key n = Vect (finToNat n) (Mod 256) -- should be Byte, but can’t convert yet
public
data AllegedRivestCipher4 : KeySize -> Type where
ARC4 : ARC4Key n -> AllegedRivestCipher4 n
KSA : ARC4Key n -> Vect 256 (Mod 256)
KSA {n=n} key =
fst (nextJ 0 0 (map Prelude.Classes.fromInteger (fromList [0..255]))) where
nextJ : Mod 256 -> Mod 256 -> Vect 256 (Mod 256)
-> (Vect 256 (Mod 256), Mod 256)
nextJ i j S = let newJ = the (Mod 256) (j + index (cast i) S + index (cast i `mod` n) key)
in (swap (cast i) (cast newJ) S, newJ)
-- ./Data/Crypto/Encryption/ARC4.idr:26:11:When elaborating right hand side of Data.Crypto.Encryption.ARC4.KSA, nextJ:
-- Can't resolve type class Cast (Mod (fromInteger 256)) (Fin (finToNat n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment