Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Hex String XOR

by moritz (Cardinal)
on Mar 12, 2012 at 09:02 UTC ( #959088=note: print w/ replies, xml ) Need Help??


in reply to Hex String XOR

You need to pack the hex representation into a binary string, so if you have '112233' you need to create the bytes "\x11\x22\x33". Then you can use the bitwise operators on these byte strings to do what you want.

Here's a nice way to do the conversions:

use strict; use warnings; use 5.010; # just needed for say() sub unascii { pack 'h*', $_[0]; } sub ascii { unpack 'h*', $_[0]; } say ascii unascii('aabbcc') ^ unascii('112233'); # output: bb99ff

See pack, unpack and perlpacktut for more details.

Replies are listed 'Best First'.
Re^2: Hex String XOR
by ikegami (Pope) on Mar 12, 2012 at 18:45 UTC

    "unascii" and "ascii" aren't very clear to me. I would call them "hex_to_bytes" and "bytes_to_hex" respectively.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://959088]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2016-07-02 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (19 votes). Check out past polls.