私は一般化されたシーザー暗号を行うための小さなプログラムを書いた。私は解読のための私の無理な力の機能が働いていない理由を理解できません。私がしようとしているのは、乗数とオフセットが26未満のすべての可能な組み合わせを試してみることです。また、誰かが "tryallcombinations"関数のより良いアプローチを提案できるなら、それは高く評価されます。ランダムなハスケルバグ。計算が決して終わらない
import Data.Char
caesarencipher::Int->Int->String->String
caesarencipher r s p = map chr $ map encipher plaintext
where
plaintext = map (\x->(ord x) - 97) p
encipher p = (mod (r*p + s) 26) + 97
caesardecipher::Int->Int->String->String
caesardecipher r s c = map chr $ map decipher ciphertext
where
ciphertext = map (\x->(ord x) - 97) c
inverser x | mod (r * x) 26 == 1 = x
| otherwise = inverser (x + 1)
decipher c = (mod ((inverser 1) * (c - s)) 26) + 97
tryallcombinations::String->[String]
tryallcombinations ciphertext = map (\x->x ciphertext) possibilities
where
rs = map caesardecipher [0..25]
possibilities = concat $ map (\x-> map x [0..25]) rs
'(\ x-> x暗号文)'はセクション化された '$'と同じです。 '($ ciphertext)' –