I just need to add a simple low-grade encryption to my site (both client side and server-side, so I need to "translate" the following into javascript):
Now my question is what are the "^" in the code and how do I do that in javascript?Code:#!/usr/bin/perl print "enter string to xor: "; chomp ($str=<stdin>); my $line = '~' x 70; print "\n"; print "$line\n"; $random = random_string(length($str)); $crypt = $str ^ $random; $restored = $crypt ^ $random; print "Message string: $str\n"; print "Random string: $random\n"; print "Crypted string: $crypt\n"; print "Restored string: $restored\n"; print "\n"; print "$line\n"; #------------------------------------------------- # a random string of the same length as the # message is generated.. thats than # XOR'ed, character-by-character, on the # message, the result is mixed but when # you XOR this mix with the same random string, # you get the original message back #------------------------------------------------- sub random_string { my $ret; for (1 .. $_[0]) { $ret .= chr(rand 256) } return $ret; }
If you need to know, I'm trying to set up a high score thing on a few javascript games that I downloaded, and my plan is to encrypt the high score, set it in a cookie (so the cookie can't easily be duplicated), and then retrieve it via this perl script. Hopefully I'll get it to work.
Well if you have an easier solution to my high score thing, please share the wealth![]()




Reply With Quote