我正在編寫一個編碼項目,我們需要在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