Posted By

szsk on 06/05/08


Tagged

ruby base64


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

sergeizen
banzaiman
webstic


base64 enocde/decode


 / Published in: Ruby
 

  1. def decode_base64( text )
  2. text.unpack( "m" )[0]
  3. end
  4.  
  5. def encode_base64( bin )
  6. [ bin ].pack( "m" ).gsub( /\s/, "" )
  7. end
  8.  
  9.  
  10.  
  11. text = "The quick brown fox jumps over the lazy dog"
  12.  
  13. p encode_base64( text )
  14. # => VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==
  15. p decode_base64( encode_base64( text ) )
  16. # => The quick brown fox jumps over the lazy dog

Report this snippet  

You need to login to post a comment.