일반화 된 시저 암호를 작성하는 작은 프로그램을 작성했습니다. 왜 암호 해독 기능이 작동하지 않는지 알 수 없습니다. 내가하려고하는 모든 것은 곱셈기와 오프셋 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)'는 섹션 화 된'$'와 동일합니다. '($ ciphertext)' –