I have found an elegant and efficient solution to the problem
posed in the appended msg: given y which is computed by
   y=: (c{a.) (256|m b.)&.(a.&i.) a.
or
   y=: a. (256|m b.)&.(a.&i.) c{a.
where atom c e. i.256 and atom m e. 16+i.16, then ff y are 
2 integers such that
   y -: (c1{a.) (256|m1 b.)&.(a.&i.) a. [ 'c1 m1'=. ff y

ff=: 3 : 0 " 1
 assert. ((,256)-:$y) *. 2=3!:0 y
 'i j'=. a.i.0 255{y
 if.     i=0     do. cm=. j,17 
 elseif. j=i     do. cm=. i,19
 elseif. j=255   do. cm=. i,23
 elseif. j=255-i do. cm=. i,22
 elseif. j=0     do. cm=. i,18
 elseif. i=255   do. cm=. j,27 
 elseif. 1       do. assert. 0 [ 'y is not generated by m b.' end.
 assert. y -: (c{a.) (256|m b.)&.(a.&i.) a. [ 'c m'=. cm
 cm
)

For example:

   'c m'=: 0 16+?256 16
   c
110
   m
19
   y=: c (256|m b.)&.(a.&i.) a.
   y=: (c{a.) (256|m b.)&.(a.&i.) a.
   ff y
110 19
   y -: (110{a.) (256|19 b.)&.(a.&i.) a.
1
   
   'c m'=: 0 16+?256 16
   c
54
   m
25
   y=: a. (256|m b.)&.(a.&i.) c{a.
   ff y
201 22
   y -: (201{a.) (256|22 b.)&.(a.&i.) a.
1
   ff a.{~ ?~256
|assertion failure: ff
|   0['y is not generated by m b.'

Exhaustive test on all possibilities:

   $ ff (16+i.16) 4 : 'y  (256|x b.)&.(a.&i.) a.'"0/a.
16 256 2
   $ ff (16+i.16) 4 : 'a. (256|x b.)&.(a.&i.) y '"0/a.
16 256 2



----- Original Message -----
From: "Roger Hui" <[EMAIL PROTECTED]>
To: Programming forum <[email protected]>
Date: Tuesday, September 25, 2007 12:06:35 HKT
Subject: Re: [Jprogramming] Decoding

Suppose

c=: ?256
d=: 16+?16
e=: a.{~ c (d b.) i.256
NB. e is used as:   map=: e {~ a. i. ]

Can you recover c and d given e?  c and d are not
necessarily unique so it suffices to compute c1 and d1
such that   e -: a.{~ c1 (d1 b.) i.256 .
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to