public
Last active

Encode a Ruby program into a version composed almost entirely of unicode whitespace characters. Decodes itself on the fly.

  • Download Gist
whitespace-a-like.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#!/usr/bin/env ruby
# encoding: utf-8
 
CHARS = %w{                       ​ ‌ ‍    }
 
def encode(string)
string.chars.map{|c|"#{CHARS[c[0]/16]}#{CHARS[c[0]%16]}"}.join
end
 
program = <<-EOF
what_to_say = 'Hello World!'
puts "This program will say \\"\#{what_to_say}\\" ten times:"
10.times{puts what_to_say}
EOF
 
File::open('ciphered.rb', 'w') do |f|
f.puts "#!/usr/bin/env ruby\n# encoding: utf-8\nh=Hash[%w{                       ​ ‌ ‍    }.zip((0..15).to_a)]"
f.puts "eval('#{encode(program)}'.chars.each_slice(3).map{|c|h[c.join]}.each_slice(2).map{|a|((a[0]*16)+a[1]).chr}.join)"
end
 
# sample output written into ciphered.rb:
#
# #!/usr/bin/env ruby
# # encoding: utf-8
# h=Hash[%w{                       ​ ‌ ‍    }.zip((0..15).to_a)]
# eval('                         ‍         ‌ ‌           ‌                                           ‍       ‌ ‌           ‌     ​                       ‍ ‌                 ‍                     ‍     ​                                 ‍  '.chars.each_slice(3).map{|c|h[c.join]}.each_slice(2).map{|a|((a[0]*16)+a[1]).chr}.join)
#
# sample output of running ciphered.rb:
#
# This program will say "Hello World!" ten times:
# Hello World!
# Hello World!
# Hello World!
# Hello World!
# Hello World!
# Hello World!
# Hello World!
# Hello World!
# Hello World!
# Hello World!

Wonderfully useless :)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.