Текст в список бит
This commit is contained in:
@@ -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)
|
||||
let encryptedText = encryptCaesar alphabet caesarShift inputText
|
||||
putStrLn $ take 30 encryptedText
|
||||
putStrLn $ concat (take 30 (map show (textToBits encryptedText)))
|
||||
@@ -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] ]
|
||||
|
||||
Reference in New Issue
Block a user