Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Enigma where
  2.  
  3. import Data.Char
  4.  
  5. import Data.List
  6.  
  7.  
  8.  
  9. cipher::String
  10.  
  11. cipher = "EKMFLGDQVZNTOWYHXUSPAIBRCJ"
  12.  
  13.  
  14.  
  15. plain::[Char]
  16.  
  17. plain = ['A'..'Z']
  18.  
  19.  
  20.  
  21. validateCipher::[Char]->Bool
  22.  
  23. validateCipher ch = (sort cipher == plain)
  24.  
  25.  
  26.  
  27. offsetCipher::Int->[Char]->[Char]
  28.  
  29. offsetCipher int cipher = drop (26-int) cipher ++ take (26-int) cipher
  30. {-
  31. getIndex :: [Char] -> Char -> Int
  32. getIndex lst i =
  33. if (head lst) == i
  34. then 0
  35. else
  36. 1 + (getIndex (tail lst) i)
  37.  
  38. -}
  39.  
  40.  
  41. encode::Char->Int->[Char]->Char
  42.  
  43. encode ch int cipher =
  44.     (offsetCipher int cipher)!!(elemIndex ch plain === Just 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement