27c3_Punycode encoder by J-_-L

#!ruby -n
s=proc{|d|d+(d<26?97:22)}
i=chomp.unpack'U*'
n=128
f=700
d=0
b=72
o=i.select{|j|j<n}
h=o.size+1
o<<45if[]!=o
(d-=(n-n=i.select{|e|e>=n}.min)*h
i.map{|j|d+=1if j<n
(q=d;k=B=36
(o<<s[T+(x=q-T)%(v=B-T)]
q=x/v
k+=B)until q<T=k<=b ?1: k>=b+26?26: k-b
o<<s[q]
w=d./f
f=2
w+=w/h
d=k=0
(w/=35;k+=B)while 455<w
b=k+B*w/(w+38)
h+=1)if j==n}
d+=1
n+=1
)until h>i.size
puts o.pack'C*'

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

download

return top