Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27031
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Base64 encoding |
| Date | 2015-03-14 12:45 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87lhizu4qi.fsf@bsb.me.uk> (permalink) |
| References | <0f320550-d218-40ea-9e9b-43a01ab53b6b@googlegroups.com> <87sid7u9tj.fsf@bsb.me.uk> <5648c915-2e25-40ad-9d21-70a6c0125320@googlegroups.com> <374b5df7-86b8-4288-907f-ff1e22628cf1@googlegroups.com> <db80772b-a929-4fd3-958e-940a388c0b55@googlegroups.com> |
jonas.thornvall@gmail.com writes: > Den lördag 14 mars 2015 kl. 12:20:43 UTC+1 skrev jonas.t...@gmail.com: >> Den lördag 14 mars 2015 kl. 12:12:14 UTC+1 skrev jonas.t...@gmail.com: >> > Den lördag 14 mars 2015 kl. 11:56:15 UTC+1 skrev Ben Bacarisse: >> > > jonas.thornvall@gmail.com writes: <snip> >> > > > Could the below logic represent how a conversion could be done. <snip> >> > > > 1. Get the byte values with charCodeAt >> > > > 2. Treat the bytevalues from string as base 256. >> > > > 3. Convert the base 256 value to base 10. (do not know howto go from >> > > > 256 to 64 right out of head) >> > > > 4. Convert base 10 into base 64. >> > > > 5. Map the characters upon the base 64 encoded. >> > > > >> > > > Maybe it is wrong? >> > > >> > > The main error is that the values from charCodeAt are not eight bits >> > > wide but up to 16 bits wide, but you also need to take care of the >> > > padding issue -- the number of encoded bytes may not be a multiple of >> > > three. Obviously the issue is slightly different when encoding 16-bit >> > > values. <snip> >> > But isn't the ascii table 8-bit? Yes, but ECMAScript uses 16 bit numbers to represent characters in a string. You are free to limit yourself to only encoding those strings that containing character values from 0 to 255, but there will be strings with characters outside of this range. <snip> >> Maybe i missunderstand you are you saying that three ASCII character >> encoded as 16-bit? Then it is just a subset of the ASCII character >> set allowed? > > Are they encoded as triplets? In a sense, yes. Think about how the two strings "a" and "aa" would be base-64 encoded. The encoding is specified by an RFC: https://www.rfc-editor.org/info/rfc4648 so it's not hard to find all the details. -- Ben.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Base64 encoding jonas.thornvall@gmail.com - 2015-03-13 23:15 -0700
Re: Base64 encoding Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-03-14 10:56 +0000
Re: Base64 encoding jonas.thornvall@gmail.com - 2015-03-14 04:12 -0700
Re: Base64 encoding jonas.thornvall@gmail.com - 2015-03-14 04:20 -0700
Re: Base64 encoding jonas.thornvall@gmail.com - 2015-03-14 05:01 -0700
Re: Base64 encoding Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-03-14 12:45 +0000
Re: Base64 encoding Richard Damon <Richard@Damon-Family.org> - 2015-03-14 09:46 -0400
csiph-web