import Data.Char
import Prelude
import System.IO
encode :: Char -> Int
encode x = ord x - ord 'A'
decode :: Int -> Char
decode x = chr (x + ord 'A')
shift :: (Int -> Int -> Int) -> Int -> Char -> Char
shift f x ch = decode $ f (encode ch) x `mod` 26
rightShift :: Int -> Char -> Char
rightShift = shift (-)
leftShift :: Int -> Char -> Char
leftShift = shift (-)
encodeString :: String -> [Int]
encodeString str = map encode str
vignereString :: String -> String -> String
vignereString secret plain = take len $ cycle secret
where len = length $ concat
vignereCode :: String -> String -> [Int]
vignereCode secret plain = encodeString $ vignereString
encrypt :: String -> String -> String
encrypt secret plain =
zipWith rightShift code plainNoSpace
where code = vignereCode secret plain
plainNoSpace = concat $ words plain
decrypt :: String -> String -> String
decrypt secret cipher = zipWith leftShift code cipherNoSpace
where code = vignereCode secret cipher
cipherNoSpace = concat $ words ciphererror message: main.hs:28:43: error:
* Couldn't match type `String -> String -> String' with `[Char]'
Expected type: String
Actual type: String -> String -> String
* Probable cause: `vignereString' is applied to too few arguments
In the second argument of `($)', namely `vignereString'
In the expression: encodeString $ vignereString
In an equation for `vignereCode':
vignereCode secret plain = encodeString $ vignereString
|
28 | vignereCode secret plain = encodeString $ vignereString
| ^^^^^^^^^^^^^
exit status 1发布于 2021-10-15 07:52:12
在vignereCode中,您不会向vignereString传递任何参数。我认为您应该组合encodeString和vignereString,以便将前者应用于后者。
vignereCode :: String -> String -> [Int]
vignereCode = encodeString . vignereStringhttps://stackoverflow.com/questions/69578384
复制相似问题