That code doesn't do encryption - it's just a byte-wise xor mask.

It's worse than that.

In JavaScript, as in Java, a string is a sequence of 16-bit code units. Unicode code points in the Basic Multilingual Plane are represented with one code unit, and code points from the other planes are represented with two code units (these are "surrogate pairs" in UTF-16).

In a surrogate pair the lead surrogate is in the range 0xD800 .. 0xDBFF and the trail surrogate is in the range 0xDC00 .. 0xDFFF. Unicode code points U+D800 to U+DFFF are not valid, and a JavaScript string must not contain a code unit in the range 0xD800 .. 0xDFFF that is not part of a surrogate pair.

So, in that code, if the text is "hello, world" and the key is 0xD800 then the result will be a string with 12 code units, all in the range 0xD800 .. 0xDBFF, and if that result is to be sent to the server then the client must encode it somehow (as UTF-8, say) and each code unit may be sent as the "REPLACEMENT CHARACTER" (0xEF 0xBF 0xBD in UTF-8).

Thanks,

Nicholas

--
You received this message because you are subscribed to the Google Groups "Ruby or 
Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to