XOR string in PHP with key

前端 未结 1 1138
挽巷
挽巷 2021-02-09 20:54

I need to XOR a string/text in PHP the base64 encode it, but something goes wrong:



        
1条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-09 21:14

    $mustget = 'Kw4SCQ==';
    
    $key = 'frtkj';
    $key_length = strlen($key);
    
    $encoded_data = base64_decode($mustget);
    
    $result = '';
    
    $length = strlen($encoded_data);
    for ($i = 0; $i < $length; $i++) {
        $tmp = $encoded_data[$i];
    
        for ($j = 0; $j < $key_length; $j++) {
            $tmp = chr(ord($tmp) ^ ord($key[$j]));
        }
    
        $result .= $tmp;
    }
    
    echo $result; // Josh
    

    http://ideone.com/NSIe7K

    I'm sure you can reverse it and create a function, that "crypts" the data ;-)

    0 讨论(0)
提交回复
热议问题