That is how it is supposed to work.
You might have intended to do this:
rottN=: 2 :0
D=. m (|. ; 3 u: ])&.> boxopen n
{&(; (0{::[)`(1{::[)`]}&.>/ D,:
> # '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þæö
# '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((
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 wou
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
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
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,
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 a
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.