Форматирование кода
This commit is contained in:
@@ -21,19 +21,19 @@ createAlphabetFromText (x:xs)
|
|||||||
indexOf :: (Eq t) => [t] -> t -> Int
|
indexOf :: (Eq t) => [t] -> t -> Int
|
||||||
indexOf [] _ = -1
|
indexOf [] _ = -1
|
||||||
indexOf (x : xs) target
|
indexOf (x : xs) target
|
||||||
| x == target = 0
|
| x == target = 0
|
||||||
| otherwise = 1 + indexOf xs target
|
| otherwise = 1 + indexOf xs target
|
||||||
|
|
||||||
encryptCaesar :: [Char] -> Int -> String -> String
|
encryptCaesar :: [Char] -> Int -> String -> String
|
||||||
encryptCaesar alphabet shift text = map caesarChar text
|
encryptCaesar alphabet shift text = map caesarChar text
|
||||||
where
|
where
|
||||||
caesarChar c = alphabet !! ((indexOf alphabet c + shift) `mod` length alphabet)
|
caesarChar c = alphabet !! ((indexOf alphabet c + shift) `mod` length alphabet)
|
||||||
|
|
||||||
decryptCaesar :: [Char] -> Int -> String -> String
|
decryptCaesar :: [Char] -> Int -> String -> String
|
||||||
decryptCaesar alphabet shift =
|
decryptCaesar alphabet shift =
|
||||||
encryptCaesar alphabet (alphabetLength - (shift `mod` alphabetLength))
|
encryptCaesar alphabet (alphabetLength - (shift `mod` alphabetLength))
|
||||||
where
|
where
|
||||||
alphabetLength = length alphabet
|
alphabetLength = length alphabet
|
||||||
|
|
||||||
textToBits :: String -> [Int]
|
textToBits :: String -> [Int]
|
||||||
textToBits = concatMap charToBits
|
textToBits = concatMap charToBits
|
||||||
|
|||||||
Reference in New Issue
Block a user