views:

77

answers:

1

I'm referring to http://www.codinghorror.com/blog/2005/10/equipping-our-ascii-armor.html but I'm getting drastically different results.

Does anyone know how to duplicate his blog post examples in Ruby?

A: 

You can generate a random UUID the uuidtools gem and output it as a hex string or an integer. The library also supports generating random strings:

require 'rubygems'
require 'uuidtools'

uuid = UUIDTools::UUID.random_create
puts uuid.to_s
puts uuid.to_i

puts SecureRandom.hex
puts SecureRandom.base64

There's an existing StackOverflow post which discusses converting a number (use to_i) to ASCII 85 in Ruby.

I also found Amp::Encoding::Base85 which you can use with the raw output from uuidtools'.

Jason Weathered
The link seems to work converting a uuid from decimal to hex, Integer.to_s(16) but it doesn't work at all trying to convert base 85 to anything. "[Rb*hlkkXVW+q4s(YSF0".to_i(16) => 0
Blaine
Using `Amp::Encoding::Base64`'s `decode` method and `UUID::parse_raw`, you should be able to decode a base 85 UUID into a native UUID again (which you could then convert back to hex).
Jason Weathered