Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Perl XOR

by fixu2 (Initiate)
on Sep 18, 2013 at 18:04 UTC ( #1054713=perlquestion: print w/replies, xml ) Need Help??
fixu2 has asked for the wisdom of the Perl Monks concerning the following question:

How can i write a perl script that do the following: "For a given string, perform XOR by 32 bits, and take the inverse of the XOR result as a hexadecimal value"

Replies are listed 'Best First'.
Re: Perl XOR
by Happy-the-monk (Abbot) on Sep 18, 2013 at 18:18 UTC

    "For a given string, perform XOR by 32 bits, and take the inverse of the XOR result as a hexadecimal value"

    Where have you been looking?

    Cheers, Sören

    Créateur des bugs mobiles - let loose once, run everywhere.
    (hooked on the Perl Programming language)

Re: Perl XOR
by kennethk (Abbot) on Sep 18, 2013 at 18:18 UTC
    What did you try? What worked? What didn't? This is not a code writing service, but we're happy to give pointers and help debug. See How do I post a question effectively?.

    You should find some useful guidance with Bitwise Or and Exclusive Or in perlop, sprintf's %x, and hex (or possibly unpack depending on what your input string looks like).


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: Perl XOR
by ikegami (Pope) on Sep 18, 2013 at 18:40 UTC

    What does it mean to "XOR a string by 32 bits"? Does that mean "XOR a 4-byte string with a 32-bit value"? If so,

    unpack('N', $s) ^ $val # Big-endian byte order -or- unpack('V', $s) ^ $val # Little-endian byte order

    What does it mean to "take the inverse of the XOR result as a hexadecimal value"? Hexadecimal is a string representation of a number, and strings don't have inverses.

Re: Perl XOR
by Laurent_R (Abbot) on Sep 18, 2013 at 18:46 UTC

    Some of the operators you may want to consider: | (bitwise or), ^ (bitwise xor), ~ (bitwise not). They should give you what you need if I understood your requirement correctly. Try perldoc op for more information on them.

Re: Perl XOR
by derby (Abbot) on Sep 19, 2013 at 01:20 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1054713]
Approved by Happy-the-monk
help
Chatterbox?
[Corion]: Hi Discipulus!
[marto]: hopefully you guys are also well :)
[Corion]: marto: Yeah - I'm looking for a week off in a week, even if it'll be a trip to Amsterdam ;)
[Discipulus]: oh thanks, i'm always at well as the ratchet or bucket
[Corion]: But I'm slowly starting to get into programming again - yesterday I translated my talk for YAPC::E (in Amsterdam) to English, and decided to put my Jekyll-clone to rest for the time being
[Corion]: Discipulus++ # being well is like being earnest
[marto]: hopefully next year I'll be in a position to go to Perly things in Europe :)
[Corion]: Maybe I'll use the Real Jekyll a bit to get a feel for how it actually works, and to get annoyed by it ;)
[Corion]: marto: That would be cool :) There is no kids care at Perly events unfortunately, so it's not entirely family friendly
[Corion]: I think I should define a set of (say) five projects through which I rotate from time to time, just to prevent myself from being bored/annoyed by the problems they get stuck in ;)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2017-07-27 07:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (404 votes). Check out past polls.