Link to home
Start Free TrialLog in
Avatar of DJ_AM_Juicebox
DJ_AM_Juicebox

asked on

Doing an XOR on a string?

Hi,

I am doing an XOR on a string in an objective-c application, the strings are UTF-8, unicode.

Now I'm trying to 'decrypt' the strings again in PHP, but it is not working. I have the following which works on ASCII characters I guess. It would be difficult to get the objective-c part to work in ascii only, so I'm looking to modify the PHP part to work with UTF-8. I tried just getting rid of ord() and replacing chr() with a unicode variant, but no luck.

Thanks

function XOREncryption($input)
{
    $crypt_key = "ABCDEFG";
 
    $vlen = strlen($input);
    $klen = strlen($crypt_key);
    $k = 0;
 
    for ($v = 0; $v < $vlen; $v++) {
            
        $c = ord($input[$v]) ^ ord($crypt_key[$k]);
        $input[$v] = chr($c);
 
        $k++;
        if ($k == $klen) {
            $k = 0;
        }
    }
 
    return $input;            
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Michael701
Michael701
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial