orig = "847C7B71727F7A7679793B707C7A3C747C737C7F76813B75817A79"; print orig , "\n" def test_and_print ( test_name, results ) 20.times { print "*" } print "\ntest_name: #{test_name} \nresults: \n" results.each { | r | print "#{r}, " } print "\n\n" end # see what's in each byte in the string # test_and_print( "to array", orig.to_a ) # test_and_print( "unpack with C*", orig.unpack('C*') ) #test_and_print( "one_char", orig.scan(/./) ) # see what's in each byte in the string # test_and_print( "two_chars", orig.scan(/../) ) my_results = orig.scan(/../) test_and_print( "twochars", my_results ) my_results = orig.scan(/../).map{ | c | [c.to_i(16), c.to_i(16).chr] } # test_and_print( "chr16", my_results ) my_results = orig.scan(/../).map{ | c | c.to_i(16).chr } # test_and_print( "chr16_nomap", my_results ) my_results = orig.unpack('C*').map{ | c | ("0x" + String(c)).to_i(16).chr } test_and_print( "unpack", my_results ) my_results = orig.scan(/../).map{ | c | Integer("0x" + String(c)) } test_and_print( "scan2", my_results ) for i in -32..32 my_results = orig.scan(/../).map{ | c | Integer("0x" + String(c)) + i } print "scan#{i}: " my_results.each{ | r | print r.chr } print "\n" end # scan-13: wondermill.com/goforit.html