Ronin Formatting Examples
Examples of data formatting data convenience methods provided by Ronin.
-
Unpacking a String:
"\x00\x05hello\x00".unpack(:uint16_be, :string) # => [5, "hello"]
-
Packing a Float:
0.02.pack(:double) # => "{\x14\xAEG\xE1z\x94?"
-
Packing an Array:
[0x05, "hello"].pack(:uint16_be, :string) # => "\x00\x05hello\x00"
-
Zlib inflate a String:
"x\x9c+NM.J-\x01\0\b\xd1\x02\x87AAAAAAA".zlib_inflate # => "secret"
-
Zlib deflate a String:
"secret".zlib_deflate # => "x\x9c+NM.J-\x01\0\b\xd1\x02\x87"
-
Return the SHA512 checksum of a String:
"thunder growl".sha512 # => "b2a1e560a497514dafda024f9e6fc2dfbfb178483251a708f07a88d4e157e5561604460da313ebc88dde2814ae58a15ae4085d00efb6a825a62f5be3215f5cbf"
-
Return the SHA256 checksum of a String:
"admin".sha256 # => "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918"
-
Return the SHA1 checksum of a String:
"lol train".sha1 # => "37f05f0cc2914615c580af396df5c66316112f48"
-
Return the MD5 checksum of a String:
"leet school".md5 # => "1b11ba66f5e9d40a7eef699cd812e362"
-
Packing an Integer:
0x1337.pack(:uint32_le) # => "7\x13\0\0"
-
Escaping a directory:
Path.up(7) # => #<Ronin::Path:../../../../../../..>
-
Base64 encode a String:
"hello\0world".base64_encode # => "aGVsbG8Ad29ybGQ=\n"
-
Base64 decode a String:
"c2VjcmV0\n".base64_decode # => "secret"