From 2dc18efbe472080479c5597e1e1bba34dd70a6f7 Mon Sep 17 00:00:00 2001 From: Arity-T Date: Sun, 17 Nov 2024 19:47:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D0=BA=D1=81=D1=82=20=D0=B2=20?= =?UTF-8?q?=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20=D0=B1=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab3/app/Main.hs | 4 +++- lab3/src/Lib.hs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) 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] ]