Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27015
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Xor characters in string do not work |
| Date | 2015-03-11 13:09 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87385bisue.fsf@bsb.me.uk> (permalink) |
| References | <6485665e-6cf2-44b3-9641-6d5cd629c473@googlegroups.com> |
jonas.thornvall@gmail.com writes:
XOR does work but...
> <SCRIPT LANGUAGE="Javascript">
> key="nyckel";
> cryptstr="text"
> j=1;
> i=1;
You'd be better off using var to declare these variables inside the
function "test" (though obviously you'll want to use parameters eventually).
> function test(){ document.write(key.charCodeAt[j]);
charCodeAt is a function -- use key.charCodeAt(j).
> document.write(cryptstr.charCodeAt[j]);
Ditto.
> cryptstr.charCodeAt[i]^= key.charCodeAt[j]^cryptstr.charCodeAt[i];
You can't assign to the result of charCodeAt. You can't even modify a
string using the special cryptstr[i] syntax. You need to build a new
string from the old one.
Finally, two ^ operations (as are hinted at here) are a no-op. I.e. an
XOR operation with some value is its own inverse.
> document.write(cryptstr[i]);
> }
> test();
> </script>
--
Ben.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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