我正在编写一个编码项目,我们需要在Haskell中编写一个vigenere密码。我花了几个小时,取得了一些进展,但我陷入了一个特定的部分。这是我到目前为止的代码:在Haskell中使用vigenere密码编码文本时遇到困难
--Program: VigCipher.hs
--Author: Mouse
import Data.Char
import Text.Printf
--Changes letters to their numerical value
let2int :: Char -> Int
let2int c = ord c - ord 'a'
--Changes numerical values to letters
int2let :: Int -> Char
int2let n = chr (ord 'a' + n)
--Shift letter by n mod 26 places
shift :: Int -> Char -> Char
shift n c | isLower c = int2let ((let2int c + n) `mod` 26)
| otherwise = c
--Encoding function
encode :: String -> String -> [Char]
encode key msg = [shift (26 - let2int (key !! a) | a <- as) (msg !! a) | x <- zip (cycle key)msg]
我的问题是在编码功能:我想要的功能检查和重点并应该要编码的消息都的各项指标在改变焦炭。我的印象是我应该工作,但是当我运行它时,由于|,我得到了解析错误在:(key !! a)|一个< - as)。我不知道如何解决这个问题,更不用说如何真正让程序检查/更改每个索引处的字母,就像我想要的那样。有人可以帮忙吗?
如果包含错误 – 2013-02-27 19:56:15