From: Todd Benson Date: 2009-05-06T05:56:57+09:00 Subject: Re: Base62 encoding/decoding On Tue, May 5, 2009 at 1:10 PM, Srikanth Jeeva wrote: > Hi, > can anyone help me in base62 encoding?? > > if i Encode "ilovemyworld" i should get a code with format[A-Za-z0-9]. > If i decode the format, i should get back "ilovemyworld" > > For Example, > encode "ilovemyworld" # eDr4e3S > decode "eDr4e3S" # ilovemyworld Would make for a good ruby quiz. I don't think it's possible, though, unless you change your intermittent base. 64 is there because "111111".to_i(2) is 63. In other words the information you store by bits (0 and 1) will have to cover the gamut of 64 characters and no less. Now, you can limit the number of characters to 32 (using 5 bits), if you're willing to have the encoding severely larger. If you used something other than "bits", like a different base, I thought it would be possible, but 62 is only divisible by 2 and 31. I suppose the pragmatic approach would be to take your undesirable characters and alter them; replacing "=" with "555", for example. I never actually knew anything about base64, so thanks for getting me to learn something :-) Todd