27c3_Punycode encoder by leonid

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