diff --git a/lab3/app/Main.hs b/lab3/app/Main.hs index 87061f2..056ced4 100644 --- a/lab3/app/Main.hs +++ b/lab3/app/Main.hs @@ -2,8 +2,13 @@ module Main (main) where import Lib +caesarShift :: Int +caesarShift = 66 + main :: IO () main = do inputText <- readFile "resources/biography.txt" putStrLn $ take 30 inputText - putStrLn $ createAlphabetFromText inputText \ No newline at end of file + let alphabet = createAlphabetFromText inputText + putStrLn $ show (length alphabet) + putStrLn $ take 30 (encryptCaesar alphabet caesarShift inputText) \ No newline at end of file diff --git a/lab3/src/Lib.hs b/lab3/src/Lib.hs index 47ce077..117a89d 100644 --- a/lab3/src/Lib.hs +++ b/lab3/src/Lib.hs @@ -1,6 +1,7 @@ module Lib ( - createAlphabetFromText + createAlphabetFromText, + encryptCaesar ) where createAlphabetFromText :: String -> [Char] @@ -9,4 +10,15 @@ createAlphabetFromText (x:xs) | x `elem` alphabet = alphabet | otherwise = x : alphabet where - alphabet = createAlphabetFromText xs \ No newline at end of file + alphabet = createAlphabetFromText xs + +indexOf :: (Eq t) => [t] -> t -> Int +indexOf [] _ = -1 +indexOf (x : xs) target + | x == target = 0 + | otherwise = 1 + indexOf xs target + +encryptCaesar :: [Char] -> Int -> String -> String +encryptCaesar alphabet shift text = map caesarChar text + where + caesarChar c = alphabet !! ((indexOf alphabet c + shift) `mod` length alphabet) \ No newline at end of file