[plt-scheme] Code review: garden fence encryption

From: David Van Horn (dvanhorn at ccs.neu.edu)
Date: Mon Mar 16 11:29:08 EDT 2009

Marek Kubica wrote:
> Much of the uglyness in my code is caused by build-phases &
> merge-phases which you solved way easier in `fence'. I'll definitely
> take a look at it, since most time writing my solution was spent
> writing code to create fences.

I think you should be able to design a function that computes the 
indices rather than building up a table that does the mapping as my 
solution does.  Together with a functional string permutation procedure, 
you would have a nice solution that operates in one pass over the input 
and only allocates space for the result string.  (Mine has to allocate 
twice that -- once for the result, once for the permutation list).

Such a fence function is easy if the width is a multiple of the fence 
height.  Things get messy in general though.  I wasn't able to figure it 
out late last night.

Let us know what you come up with.

David


Posted on the users mailing list.