Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: State help request (Joe)
2. Re: State help request (David McBride)
----------------------------------------------------------------------
Message: 1
Date: Sun, 9 Dec 2012 17:39:58 -0500
From: Joe <[email protected]>
Subject: Re: [Haskell-beginners] State help request
To: David McBride <[email protected]>
Cc: [email protected]
Message-ID:
<CAL5YfcKoe3Q9X_7SG7Fj42+FAoTMSjQJvEKZKQQpH3Q7=mp...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Thanks for your help, not sure why I'd put the key in the State. The
execState and pointfree-ing made it a lot nicer. You're right on the
foldr/flip, but I wasn't zeroing the i & j parts of the PRGA, so now I
have:
ksa' :: Key -> PRGA
ksa' key = (prga,0,0) -- have to zero
where (prga,_,_) = foldr (execState . ksaStep' key) (permId,0,0)
[255,254..0]
I need the [255,254..0] since it has to count up, and the "where" to
set the zeros. I'm not sure if those are worth fixing, or what can be
done to make either of those any better. Any suggestions would be
appreciated.
As for running, I was just running "pwCrypt "key" "plaintext"" in ghci
and checking against the expected keystream/ciphertext.
> And man I just want to say how jealous I am. I wish I could go to a ny
> haskell group :(.
There's a meeting this week! Edward Kmett and his lens library. Last
month's had a good crowd, very friendly.
------------------------------
Message: 2
Date: Sun, 9 Dec 2012 18:04:31 -0500
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] State help request
To: Joe <[email protected]>
Cc: [email protected]
Message-ID:
<can+tr43dvk5yjrrju4dgch-9+2wj5y-rwwzmmzlhfpvqugu...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
>From looking at the code I see that yo aren't actually using the i variable
you are storing in ksaStep' either. So to simplify the where clause you
might do this:
ksa' :: Key -> PRGA
ksa' key = (prga,0,0) -- have to zero
where prga = fst $ foldr (execState . ksaStep' key) (permId,0)
[255,254..0]
ksaStep' :: Key -> Int -> State (Vector Int, Int) ()
ksaStep' key i = do
(s,j) <- get
let j' = (j + (s!i) + (key !! (i `mod` length(key)))) `mod` 256
s' = s // [(i, s!j'), (j',s!i)]
put $ (s',j')
Which gets rid of some more unnecessary stuff. A little better I guess.
For the [255,254..0], you could always just replace it with reverse
[0.255]. It isn't a huge deal either way.
And yeah, ny is a bit far away. But you go have fun.
On Sun, Dec 9, 2012 at 5:39 PM, Joe <[email protected]> wrote:
> Thanks for your help, not sure why I'd put the key in the State. The
> execState and pointfree-ing made it a lot nicer. You're right on the
> foldr/flip, but I wasn't zeroing the i & j parts of the PRGA, so now I
> have:
>
>
> ksa' :: Key -> PRGA
> ksa' key = (prga,0,0) -- have to zero
> where (prga,_,_) = foldr (execState . ksaStep' key) (permId,0,0)
> [255,254..0]
>
>
> I need the [255,254..0] since it has to count up, and the "where" to
> set the zeros. I'm not sure if those are worth fixing, or what can be
> done to make either of those any better. Any suggestions would be
> appreciated.
>
> As for running, I was just running "pwCrypt "key" "plaintext"" in ghci
> and checking against the expected keystream/ciphertext.
>
> > And man I just want to say how jealous I am. I wish I could go to a ny
> haskell group :(.
>
> There's a meeting this week! Edward Kmett and his lens library. Last
> month's had a good crowd, very friendly.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121209/c0e34685/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 54, Issue 14
*****************************************