# 'aábcðdeéfghiíjklmnoópqrstuúvwxyýzþæö' 46 # 'AÁBCÐDEÉFGHIÍJKLMNOÓPQRSTUÚVWXYÝZÞÆÖ' 46 lc=.'aábcðdeéfghiíjklmnoópqrstuúvwxyýzþæö' uc=.'AÁBCÐDEÉFGHIÍJKLMNOÓPQRSTUÚVWXYÝZÞÆÖ' 13 rottN ((#L:0~ lc;uc) u:i.2^16) 'prófaþetta með íslenzkum stöfunum æÆöðÐþÞ' |domain error | 13 rottN(( #L:0~lc;uc)u:i.2^16)'prófaþetta með íslenzkum stöfunum æÆöðÐþÞ'
2011/12/23 Raul Miller <rauldmil...@gmail.com> > True. > > The underlying problem is that the algorithm itself is language specific. > > I do not know how to implement a consistent version of this mechanism > for German, for example. The problem with German is that ß does not > have an "upper case" variant. So rotation of lower case letters in > german would have to be different from rotation for upper case letter. > Perhaps that's acceptable? > > If it makes sense to apply the same rotation to cycles of differing > lengths, here's a version which works for the arbitrary cases > involving unicode characters which J can handle. > > NB. n: boxed character sequences to be rotated (must not overlap) > NB. m: how much to rotate them > > rottN=: 2 :0 > D=. m (|. ; 3 u: ])&.> boxopen n > {&(; (0{::[)`(1{::[)`]}&.>/ D,<u:i.2^16)@(3&u:) > ) > > 5 rottN '0123456789' '123' > 678 > > ;/a.{~65 97+/i.26 > +--------------------------+--------------------------+ > |ABCDEFGHIJKLMNOPQRSTUVWXYZ|abcdefghijklmnopqrstuvwxyz| > +--------------------------+--------------------------+ > 13 rottN (;/a.{~65 97+/i.26) 'testing' > grfgvat > 13 rottN (;/a.{~65 97+/i.26)^:2 'testing' > testing > > Or, using character selectors instead of character sequences (and > living with unicode character ordering): > > 13 rottN ((#L:0~ lc;uc) u:i.2^16) 'prófaþetta með íslenzkum stöfunum > æÆöðÐþÞ' > > But it's up to you to define lc and uc > > FYI, > > -- > Raul > > > 2011/12/23 Björn Helgason <gos...@gmail.com>: > > This is only english > > > > _1 rottn 1 rottn 'testing' > > testing > > > > Does not work with my alpha > > > > _1 rottn 1 rottn 'prófaþetta með íslenzkum stöfunum æÆöðÐþÞ' > > prófaþetta með Ãslenzkum stöfunum æÆöðà þÞ > > 3 u: 'prófaþetta með íslenzkum stöfunum æÆöðÐþÞ' > > 112 114 195 179 102 97 195 190 101 116 116 97 32 109 101 195 176 32 > > 195 173 115 108 101 110 122 107 117 109 32 115 116 195 182 102 117 110 > > 117 109 32 195 166 195 134 195 182 195 176 195 144 195 190 195 158 > > > > 3 u: 7 u: 'prófaþetta með íslenzkum stöfunum æÆöðÐþÞ' > > 112 114 243 102 97 254 101 116 116 97 32 109 101 240 32 237 115 108 > > 101 110 122 107 117 109 32 115 116 246 102 117 110 117 109 32 230 198 > > 246 240 208 254 222 > > # 3 u: 'prófaþetta með íslenzkum stöfunum æÆöðÐþÞ' > > 53 > > # 3 u: 7 u: 'prófaþetta með íslenzkum stöfunum æÆöðÐþÞ' > > 41 > > 8 u: 4 u: 3 u: 7 u: 'prófaþetta með íslenzkum stöfunum æÆöðÐþÞ' > > prófaþetta með íslenzkum stöfunum æÆöðÐþÞ > > > > # 3 u: 7 u: 'aábcðdeéfghiíjklmnoópqrstuúvwxyýzþæö' > > 36 > > # 3 u: 7 u: 'AÁBCÐDEÉFGHIÍJKLMNOÓPQRSTUÚVWXYÝZÞÆÖ' > > 36 > > > > > > > > 2011/12/23 Raul Miller <rauldmil...@gmail.com> > > > >> Here's another variation: > >> > >> rotn=: 1 :'{&((65 97 +/~ i.26) m&|.@[`[`]} i.256)&.(a.&i.)' > >> > >> 1 rotn 'testing' > >> uftujoh > >> 13 rotn 'testing' > >> grfgvat > >> 13 rotn 13 rotn 'testing' > >> testing > >> _1 rotn 1 rotn 'testing' > >> testing > >> > >> In this expression, each arbitrary constant is used only once: > >> > >> 26: letters in the alphabet > >> 65: 'A' > >> 97: 'a' > >> 256: the number of character codes > >> > >> I could replace 256 with #a. but I do not think that adds any clarity. > >> > >> That said... > >> rottn=: 1 :'{&((65 97 +/~ i.26) m&|.@u:@[`[`]} a.)&(3&u:)' > >> > >> -- > >> Raul > >> On Fri, Dec 23, 2011 at 11:27 AM, Raul Miller <rauldmil...@gmail.com> > >> wrote: > >> > Wait, bad idea... that rot13 only works because 13 is a factor of 26. > >> > > >> > Instead (and this is a fast bug fix, I have not thought much about > >> > more elegant forms, though several paths for rephrasing come to mind): > >> > > >> > rotN=: 1 :'{&((65 97 +/ m |. i.26) ((65 97 +/i.26)}) i.256)&.(a.&i.)' > >> > > >> > -- > >> > Raul > >> > > >> > On Fri, Dec 23, 2011 at 11:21 AM, Raul Miller <rauldmil...@gmail.com> > >> wrote: > >> >> Here's what I use for rot13: > >> >> > >> >> rot13=: {&((65 97+/~i.2 13) |.@[} i.256)&.(a.&i.) > >> >> > >> >> If I wanted to generalize that, I would probably go with: > >> >> > >> >> rotN=: 1 :'rot13=: {&((65 97+/~i.2,m) |.@[} i.256)&.(a.&i.)' > >> >> > >> >> 13 rotN 'testing' > >> >> grfgvat > >> >> 13 rotN rot13 'testing' > >> >> testing > >> >> > >> >> -- > >> >> Raul > >> >> > >> >> On Fri, Dec 23, 2011 at 11:00 AM, Lorenzo Costanzia di Costigliole > >> >> <lorenzo.costan...@gmail.com> wrote: > >> >>> NB. What is the most elegant way to rotate uppercase > >> >>> NB. and lowercase letters by n? ("rotation cipher") > >> >>> > >> >>> c2n=: a.&i. > >> >>> > >> >>> lc=: >&96 *. <&123 > >> >>> uc=: >&64 *. <& 91 > >> >>> > >> >>> s=: 'Btggn Rwgxhibph 2011 id iwt Y-Egdvgpbbxcv bpxaxcv axhi!' > >> >>> > >> >>> > >> >>> > >> >>> NB. I came up with those, but I think there’s still room for > >> improvement > >> >>> NB. (Isn't there something in the J-Phrases?) > >> >>> > >> >>> NB. uppercase -> 2, lowercase -> 1, else -> 0 > >> >>> cl=: +:@uc + lc > >> >>> cl`(] , ([: 26&| +&n)&.(-&97) ,: ([: 26&| +&n)&.(-&65))}&.c2n s > >> >>> > >> >>> ((] + ] ]`([: 26&| n + ])@.((0~:[)"0) [ - ]) (97&*@lc + > 65&*@uc))&.c2n > >> s > >> >>> > >> >>> NB. Enumerate all possibilities > >> >>> |: ((] + ] (26 # ])`([: 26&| (i.26) + ])@.((0 ~: [)"0) [ - ]) > (97&*@lc > >> >>> + 65&*@uc))&.c2n s > >> >>> > >> >>> NB. Thanks! > >> >>> > ---------------------------------------------------------------------- > >> >>> 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 > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm