Skip to content

Instantly share code, notes, and snippets.

@dustinlacewell
Last active September 7, 2021 03:42
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 dustinlacewell/a4e877326775198bf1e52243080656e9 to your computer and use it in GitHub Desktop.
Save dustinlacewell/a4e877326775198bf1e52243080656e9 to your computer and use it in GitHub Desktop.
encrypt :: Key -> String -> String
encrypt k =
mapWithIdx (\i c ->
let j = k !! (i `mod` keylen)
n = nForChar j
in rotate n c)
where keylen = Prelude.length k
decrypt :: Key -> String -> String
decrypt k =
mapWithIdx (\i c ->
let j = k !! (i `mod` keylen)
n = negate (nForChar j)
in rotate n c)
where keylen = Prelude.length k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment