Skip to content

Instantly share code, notes, and snippets.

@Mic92
Created April 14, 2012 20:27
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 Mic92/2387761 to your computer and use it in GitHub Desktop.
Save Mic92/2387761 to your computer and use it in GitHub Desktop.
Algebra - 8. Hausaufgabe
import Data.Char
alphabet = ['A'..'Z']++['ß','Ä','Ö','Ü']
charToInteger :: Char -> Integer
charToInteger char = maybe 0 id isValue
where charMap = zip alphabet [0..29]
isValue = lookup (toUpper char) charMap
integerToChar :: Integer -> Char
integerToChar int
| 0 > int || int > 29 = ' '
| otherwise = alphabet !! (fromInteger int)
decrypt :: Integer -> Integer -> [Char] -> [Char]
decrypt d n crypt = map integerToChar plain
where nums = map charToInteger crypt
plain = map (\m -> ((m `mod` n)^d) `mod` n) nums
main = print $ (decrypt 13 31 $ decrypt 7 31 "ÄMDARQYC") == "ÄMDARQYC"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment