Haskell で vigenere cypher を作成する必要があるコーディング プロジェクトに取り組んでいます。私は何時間も費やしましたが、ほとんど進歩がありませんでしたが、特定の部分で立ち往生しています。これまでの私のコードは次のとおりです。
--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]
私の問題は Encoding 関数にあります。関数で、キーとエンコードされるはずのメッセージの両方のインデックスごとに char を調べて変更する必要があります。私が持っているものはうまくいくはずだという印象を受けていますが、実行すると | のために解析エラーが発生します。in: (キー !! a) | a <-as)。それを修正する方法がわかりません。ましてや、プログラムが実際に各インデックスで文字を調べたり変更したりする方法もわかりません。誰か助けてくれませんか?