Текст в список бит

This commit is contained in:
2024-11-17 19:47:13 +03:00
parent ef9f0448e4
commit 2dc18efbe4
2 changed files with 13 additions and 3 deletions

View File

@@ -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)
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] ]