diff --git a/lab3/app/Main.hs b/lab3/app/Main.hs index 056ced4..70ebd09 100644 --- a/lab3/app/Main.hs +++ b/lab3/app/Main.hs @@ -11,4 +11,6 @@ main = do putStrLn $ take 30 inputText let alphabet = createAlphabetFromText inputText putStrLn $ show (length alphabet) - putStrLn $ take 30 (encryptCaesar alphabet caesarShift inputText) \ No newline at end of file + let encryptedText = encryptCaesar alphabet caesarShift inputText + putStrLn $ take 30 encryptedText + putStrLn $ concat (take 30 (map show (textToBits encryptedText))) \ No newline at end of file diff --git a/lab3/src/Lib.hs b/lab3/src/Lib.hs index 117a89d..dce7c5e 100644 --- a/lab3/src/Lib.hs +++ b/lab3/src/Lib.hs @@ -1,9 +1,13 @@ module Lib ( createAlphabetFromText, - encryptCaesar + encryptCaesar, + textToBits ) where +import Data.Char (ord) +import Data.Bits (testBit) + createAlphabetFromText :: String -> [Char] createAlphabetFromText [] = [] createAlphabetFromText (x:xs) @@ -21,4 +25,8 @@ indexOf (x : 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 + caesarChar c = alphabet !! ((indexOf alphabet c + shift) `mod` length alphabet) + +textToBits :: String -> [Int] +textToBits = concatMap charToBits + where charToBits c = [ if testBit (ord c) i then 1 else 0 | i <- [7,6..0] ]