Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #27020

Re: Xor characters in string do not work

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Xor characters in string do not work
Date 2015-03-12 15:43 +0100
Organization PointedEars Software (PES)
Message-ID <3767006.WovHSH5Fpe@PointedEars.de> (permalink)
References <6485665e-6cf2-44b3-9641-6d5cd629c473@googlegroups.com> <87385bisue.fsf@bsb.me.uk> <8fdd532b-a5d9-41db-8f95-fd0975b2f77a@googlegroups.com> <mdpjpn$b2l$1@adenine.netfront.net>

Show all headers | View raw


Martin Honnen wrote:

> jonas.thornvall@gmail.com wrote:
>> Do i really need to loop with charCodeAt building up the string?
>> Or is there better way
>>
>> for (i=0;i<key.length;i++) keyarr[i]=key.charCodeAt(i);

More efficient “for” loops are written this way:

  for (var i = 0, len = key.length; i < len; ++i)
  {
    // …
  }

>> This seem a bit primitive is there no other way to simply remap the
>> characters from a full string into an array.
>>
>> Let me dream a little keyarr=key.charCodeStr()
>> Voila it is done.
> 
> You can (at least in JavaScript) treat a string like an array and use
> the "map" method:

Array.prototype.map() is supported by several implementations of ECMAScript 
Ed. 5 and later:

<http://PointedEars.de/es-matrix/?filter=map>
 
> var s = "abc";
> var a = [].map.call(s, function(ch) { return ch.charCodeAt(); });

or

  var a = s.split("").map(function (ch) { return ch.charCodeAt(); });

> But of course strings are sequences of 16 bit Unicode characters not of
> 8 bit values.

No, String values are, unfortunately, defined in ECMAScript (up to including 
the 5.1 Edition) as “sequences of 16-bit units” only.  Therefore, the built-
in String properties do not work for Unicode characters beyond the Basic 
Multilingual Plane (BMP).

Remedy:
<http://PointedEars.de/wsvn/JSX/trunk/string/unicode.js> and the like.

> --- news://freenews.netfront.net/ - complaints: news@netfront.net ---

Eeek.  Must you use *that*?  It is a known source of trolls.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Xor characters in string do not work jonas.thornvall@gmail.com - 2015-03-11 04:44 -0700
  Re: Xor characters in string do not work Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-03-11 13:09 +0000
    Re: Xor characters in string do not work jonas.thornvall@gmail.com - 2015-03-11 06:49 -0700
      Re: Xor characters in string do not work Martin Honnen <mahotrash@yahoo.de> - 2015-03-11 15:34 +0100
        Re: Xor characters in string do not work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-03-12 15:43 +0100
      Re: Xor characters in string do not work Scott Sauyet <scott.sauyet@gmail.com> - 2015-03-11 07:52 -0700

csiph-web