Skip to content

Instantly share code, notes, and snippets.

@nelsnelson
Created February 19, 2011 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelsnelson/834940 to your computer and use it in GitHub Desktop.
Save nelsnelson/834940 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
n=ARGV.first.to_i; charset='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 '.split(//)
def generate(charset, n)
(0..n).map{(0..17).map{charset[rand(charset.length)]}.join.unpack('H*').join.scan(/.{2}/).join(' ') }
end
def decode(samples)
samples.map{|x|x.split.map{|a|a.to_i(16)}.pack('c*')}
end
samples = generate(charset, n)
s = decode(samples)
puts s unless ARGV[1] == "-q"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment