Created
April 14, 2012 20:27
-
-
Save Mic92/2387761 to your computer and use it in GitHub Desktop.
Algebra - 8. Hausaufgabe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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