Skip to content

Instantly share code, notes, and snippets.

@hooopo
Created December 14, 2009 09:35
Show Gist options
  • Save hooopo/255938 to your computer and use it in GitHub Desktop.
Save hooopo/255938 to your computer and use it in GitHub Desktop.
#utf-8
def encode(str)
keys = "abcdefghijklmnopqrstuvwxyz234567"
str.unpack("C*").map{|b| "%08b" % b}.join.scan(/\d{1,5}/).map{|x| "0" * 3 + x.ljust(5,"0")}.map{|y| keys[y.to_i(2)].chr}.join
end
p encode "aaa" #=> "mfqwc"
p encode "JavaEye论坛频道" #=>"jjqxmykfpfs6rlv24wozx2ncshuydey"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment