Jump to content


XOR a string 1 character at a time

  • Please log in to reply
1 reply to this topic

#1 soadlink

  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 14 October 2006 - 09:45 PM

Hello I need some help with code where I could store a string as $string and then XOR it 1 character at a time by the phrase "gamespy".

So if I have HelloWorld for my string, I want to XOR the H, then the e, then the l.... and so on until the string is done. Then I want to echo the XOR conversions together. I am bascially trying to port the C code blow over to PHP, or even over to VB would be nice (just a way that will help me understand it)

but here is the original C code
void gamespyxor(u_char *data, int len) {
    u_char  gamespy[] = "gamespy",

    for(gs = gamespy; len; len--, gs++, data++) {
        if(!*gs) gs = gamespy;
        *data ^= *gs;

Enjoy the silence

#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 15 October 2006 - 01:12 AM

You can access the ith character of a string using $string{$i}

$string = 'HelloWorld';

$lens = strlen($string);

for ($i=0; $i < $lens; $i++) {
    echo $string{$i} . '<br />';

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users