Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: strings to number and XOR

by alager (Acolyte)
on Oct 07, 2009 at 17:52 UTC ( #799771=note: print w/ replies, xml ) Need Help??


in reply to Re: strings to number and XOR
in thread strings to number and XOR

Last question, then I should be done. :)
For the variable
$key = "\x4f\xcb"; How can I increment it?
I've tried directly with $key++, but that starts counting at 0, I would expect \x4f\xcc as the result.

And I've tried unpacking it. Which starts incrementing with the first number (4 in this case) and loses the rest of the data. eg 4,5,6...
I would like
0x4fcb 0x4fcc 0x4fcd ect.

Thanks,
Aaron

UPDATE: I've found part of the problem, perl doesn't like to add numbers that aren't "numbers", this works fine as long as my bytes are in the range of ASCII numbers, but fails for values above outside of 0x30-0x39.


Comment on Re^2: strings to number and XOR
Download Code
Re^3: strings to number and XOR
by almut (Canon) on Oct 07, 2009 at 18:23 UTC
    I've tried directly with $key++

    The problem with Perl's string-increment is that the string has to match the pattern /^[a-zA-Z]*[0-9]*\z/ for it to work...(see perlop).  So you'd have to increment the corresponding numeric value, e.g.

    $key = "\x4f\xcb"; for (1..10) { $key = pack('n',unpack('n',$key)+1); # ++ print unpack("H*", $key), "\n"; } __END__ 4fcc 4fcd 4fce 4fcf 4fd0 4fd1 4fd2 4fd3 4fd4 4fd5

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2014-07-12 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls