Skip to content

Instantly share code, notes, and snippets.

@oerpli
Created December 9, 2014 01:47
Show Gist options
  • Save oerpli/cd32885fe3480853f091 to your computer and use it in GitHub Desktop.
Save oerpli/cd32885fe3480853f091 to your computer and use it in GitHub Desktop.
ec _ [] = []
ec bla ((a,b):r) = (bla*a+b):ec bla r
e base y = (ec base) . pair $ (map (\x -> toInteger $ (ord x) - (ord 'a') +1) y)
dc _ [] = []
dc bla (a:r) = [div a bla, mod a bla] ++ dc bla r
d base y = map (\x -> " abcdefghijklmnopqrstuvwxyz" !! (length [1..x])) (dc base y) --- length [1..x] is an ugly (::Integer -> Int) hack
pair [] = []
pair (a:b:r) = (a,b) : pair r
pub =(49,3233)
priv = (2929,3233)
c :: (Integer, Integer) -> [Integer] -> [Integer]
c (key,n) message = map (\m -> mod (m^key) n) message
rsatest = d 100 $ c priv $ c pub $ e 100 "computer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment