[Haskell-beginners] Evaluation oddity
Torsten Otto
t-otto-news at gmx.de
Sun Feb 6 18:00:41 UTC 2022
Hi all,
maybe one of you sees a difference, I sure don’t… The full code for this is below.
When I call
*Main> diffieH 23 16 20
13
and use the result in
*Main> encipher "abc" 13
„nop"
I get the letters to be expected. However, when I combine these into
> start text p a b = encipher text (diffieH p a b)
*Main> start "abc" 23 16 20
„efg"
the result changes.
Any hints are most welcome.
Thank you and regards
Torsten
> import Data.Char
> diffieH p a b = (b ^ a) `mod` p
> number2letter number = chr (number + 96)
> letter2number letter = (ord letter) - 96
> start text p a b = encipher text (diffieH p a b)
> encipher [] _ = []
> encipher (b:rest) key = (number2letter (((letter2number b)+key) `mod` 26)) : (encipher rest key)
More information about the Beginners
mailing list