Map-to-integer for ciphers? (edited)

Henning Thielemann lemming at henning-thielemann.de
Sun Jul 29 09:53:44 UTC 2018


On Sun, 29 Jul 2018, 박신환 wrote:

> instance forall a. (Cipherable a, Bounded a) => Cipherable [a] where
>     deCipher 0 = []
>     deCipher n = let
>         (q,r) = (n-1) `quotRem` (1 + enCipher (maxBound :: a))
>         in deCipher r : deCipher q

let (q,r) = (n-1) `quotRem` (1 + enCipher (maxBound `asTypeOf` rd))
     rd = deCipher r
in  rd : deCipher q

>     enCipher []     = 0
>     enCipher (x:xs) = 1 + enCipher x + (1 + enCipher (maxBound :: a)) * fromEnum xs

maxBound `asTypeOf` x


More information about the Libraries mailing list