27c3_Punycode encoder by narb (leonid)

#!ruby -n
i=chomp.unpack'U*'
b=700
a=72
d=-1
$><<:-if 0<h=i.count{|j|putc(j)if j<N=127}
i.map{|j|j<N&&d+=1
j==N&&(z=d/b
b=2
(putc (T+49+(d-=T)%v=36-T)%75+48;d/=v)until d<T=[1,-a-=36,26].sort[1]
putc 97+d
z+=z/h-=~a=0
z/=35%a+=36while z>455
a+=36*z/z+=38
d=0)}while i[h]?d-=(~N+N=i.sort[h])*~h-1:puts

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page