CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Quick encryption help needed...

 



Merlin
journeyman

Sep 25, 2000, 1:10 PM

Post #1 of 4 (512 views)
Quick encryption help needed... Can't Post

Ok, a friend of mine who is a quack at crytpography told me a quick way to encrypt is to XOR strings and numbers. The XOR, combined with a key, acts as a toggle to encrypt, decrypt strings or numbers. This all seems fine in theory but I'm having problems implementing the real thing. I read there is no real XOR operator in Perl. Is that true? Would there be a way around this? I found in O'reilly's Programming Perl that there is a sort of XOR (^) but it only works on bits. Would that help? I'm trying to do stuff like :
$encrypte = $string ^ $encryptionkey;
and then back again, with $string values that contain numbers, caracters or both. Thanks!


dws
Deleted

Sep 27, 2000, 12:15 PM

Post #2 of 4 (512 views)
Re: Quick encryption help needed... [In reply to] Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

print "abcde" ^ "XYZZY"</pre><HR></BLOCKQUOTE>
The XOR is bitwise on the characters. Just make sure both strings are the same length.


japhy
Enthusiast

Sep 27, 2000, 1:23 PM

Post #3 of 4 (512 views)
Re: Quick encryption help needed... [In reply to] Can't Post

You may have been told that there is no LOGICAL XOR operator in Perl. That is false. 'xor' is the logical XOR operator. What IS true is that there is no SYMBOLIC logical XOR operator (we have && and 'and', &#0124; &#0124; and 'or', but nothing for 'xor').

The bitwise XOR operator is ^. (There is NO ^^ operator.) It works on numbers (in a binary sense) and strings (in a character sense).

To see a little document of mine on using one-time pass (OTP -- the XOR cryptographic method), see http://www.pobox.com/~japhy/doc/CRYPT_AND_OTP at my web site.

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher



Merlin
journeyman

Oct 5, 2000, 5:57 AM

Post #4 of 4 (512 views)
Re: Quick encryption help needed... [In reply to] Can't Post

Thanks for the info! I was missing out on the fact I needed to have a same length string to encode and decode the data. Since I need the encoding and decoding to be done on variable length data and on different scripts, I guess I can create an encryption string as long as the biggest string I need to encrypt and truncate the key for smaller strings. Thanks!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives