dblprocess=: (#!.'x'~ 1 j. i.@# = (2* 1 i.~ (_2 (=/`0:@.(2|#))\ ])))
::]^:_
   preprocess=: [: ,&'x'^:(1=2|#) dblprocess

Provides a moderately blunt preprocessor. Things I'd like fixed:
(_2 (=/`0:@.(2|#))\ ])) should just be (_2 =/\ ]) , but on an odd length
string the last part, say (=/\ 'e') , gives a single character and not a
Boolean, resulting in a domain error.
Does anyone know a better way to do insertion with an index than using # ?

   preprocess 'allisdiscoveredflee'
allisdiscoveredfleex
   preprocess 'xallisdiscoveredflee'
xalxlisdiscoveredfleex
   preprocess 'xallisdiscoveredxflee'
xalxlisdiscoveredxflexex

Marshall

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Henry Rich
Sent: Saturday, February 19, 2011 1:40 PM
To: Programming forum
Subject: Re: [Jprogramming] Playfair cipher

Oh yeah,

    pf =. 'paswo','rdbce','fghik','lmnqt',:'uvxyz'

(thanks Ric)

Henry Rich

On 2/19/2011 11:39 AM, Henry Rich wrote:
> I worked on the easy part:
>
>      pfr =. ((] (<"1@[ { ])~ ((0 1&(|."_1)&.|:@[)`(-"1 |.)@.(+./@]) 
> =/) @ ($@] #: (i.~ ,))) ];.0)~
>
>      ; _2 pf&pfr\ 'allisdiscoveredfleex'
> pmqfabhwewzddrrgtrbz
>
>      ; _2 (];.0 pf)&pfr\ 'pmqfabhwewzddrrgtrbz'
> allisdiscoveredfleex
>
> I can now add monad u;.0 to my Life List.
>
> (you would also need a preconditioner to handle double letters and 
> odd-length input).
>
> I was hoping the same program would work for the hard part, but I 
> wasn't sure what to do when the two letters match in more than one axis.
>
> Henry Rich
>
>
> On 2/19/2011 7:40 AM, Kip Murray wrote:
>> The Playfair cipher http://en.wikipedia.org/wiki/Playfair_cipher is 
>> based on a 5 by 5 character array that treats i and j as equivalent:
>>
>> paswo
>> rdbce
>> fghik
>> lmnqt
>> uvxyz
>>
>> To encode "All is discovered flee" you replace pairs of letters al li 
>> sd is co ve re df le ex with pairs diagonally opposite, one to the 
>> right, or one below (wrapping) from the table, getting
>>
>> pm qf ab hw ew zd dr rg tr bz
>>
>> Your mission, should you decide to accept it, is to write j code for 
>> enciphering and deciphering, given the five by five table.  That's 
>> the easy part.  The hard part is to design and implement an analogous 
>> cipher that uses the 3 by 3 by 3 character array below to replace 
>> triples of letters alx _is _di sco ver ed_ fle ex_
>>
>> pas
>> wor
>> dbc
>>
>> efg
>> hij
>> klm
>>
>> nqt
>> uvx
>> yz_
>>
>> ---------------------------------------------------------------------
>> - For information about J forums see 
>> http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to