From: Brian Candler Date: 2010-08-18T23:11:18+09:00 Subject: Re: Base64 multiple by 4 aaaa aaaaaaaaaaa wrote: > Brian Candler wrote: >> irb(main):001:0> s = ["hello world"].pack("m") >> => "aGVsbG8gd29ybGQ=\n" >> irb(main):002:0> s.unpack("m").first >> => "hello world" > > Once again, that's what not I wanted. Then you need to specify more precisely what you want. At a glance, the Java code you linked to implements a perfectly standard Base64 encoding (although I've not attempted to run it), which is why I gave the Ruby equivalent. You're saying it doesn't? What does it implement then? "decode a string multiplied by 4" doesn't really mean anything by itself. The Java code appears to take groups of 3 bytes and turns them into 4 characters, as Base64 does. > Heres an example of what I wanted > (and now have): > >>> RBase64.charset = (20..84).map(&:chr).join > => "\x14\x15\x16\x17\x18\x19\x1A\e\x1C\x1D\x1E\x1F > !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRST" >>> RBase64.encode "my secret string" > => "/+840J)70:)H\x1C\e!H0:9B-D==" >>> RBase64.decode "/+840J)70:)H\x1C\e!H0:9B-D==" > => "my secret string" Test vectors are certainly useful. Now, can you describe the encode/decode algorithm you're implementing, other than by means of your existing Ruby code? (Incidentally, you've only shown your decode method so far, not the encode) What character set are you using in the encoded string? Why are the unprintable characters \x1C and \e in there? -- Posted via http://www.ruby-forum.com/.