alager has asked for the wisdom of the Perl Monks concerning the following question:
I would like to xor every two bytes in an arbitrary string with the same value, or key.
Here is one things I've tried, but the result is not correct.
For the first two characters (th) xor I expect it to be 0x3ba3, but I'm getting 0x52e7, I can't figure out what is going wrong.
Thanks, Aaron#!/usr/bin/perl 2 3 $msg = "this is a test messagez"; 4 $key = 0x4fcb; 5 print "$msg\n"; 6 7 @array = split(/(..)/, $msg); 8 9 10 printf "key: %x\n", $key; 11 12 $xitem = unpack("H*", $array[1]) ^ $key; 13 print "item: $array[1] = hex " . unpack("H*", $array[1]) . "\n"; 14 printf ("xored item \'%x\', want 0x3ba3\n", $xitem);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: strings to number and XOR
by almut (Canon) on Oct 07, 2009 at 00:49 UTC | |
by Anonymous Monk on Oct 07, 2009 at 05:13 UTC | |
by alager (Acolyte) on Oct 07, 2009 at 17:52 UTC | |
by almut (Canon) on Oct 07, 2009 at 18:23 UTC | |
by Anonymous Monk on Oct 07, 2009 at 16:57 UTC | |
by Anonymous Monk on Oct 07, 2009 at 17:01 UTC | |
by almut (Canon) on Oct 07, 2009 at 17:20 UTC | |
Re: strings to number and XOR
by JavaFan (Canon) on Oct 07, 2009 at 00:40 UTC |
Back to
Seekers of Perl Wisdom