2012-12-14 9 views
6

ho bisogno di XOR una stringa/testo in PHP le base64 codificare, ma qualcosa va storto:stringa di XOR in PHP con chiave

<?php 

$mustget = 'Kw4SCQ=='; 
$string = 'Josh'; 

echo("Must get: " . $mustget . "\n"); 
echo("We got: " . base64_encode(xor_this($string)) . "\n"); 

function xor_this($text) { 
    $key = 'frtkj'; 
    $i = 0; 
    $encrypted = ''; 
    foreach (str_split($text) as $char) { 
     $encrypted .= chr(ord($char)^ord($key{$i++ % strlen($key)})); 
    } 
    return $encrypted; 
} 

?> 

ottengo il seguente risultato, ma ho bisogno di ottenere il "$ mustget "uno:

Must get: Kw4SCQ== 
We got: LB0HAw== 

Cosa faccio di sbagliato?

+1

Chi definisce "must"? – zerkms

+0

Sto lavorando alla decrittografia di un malware in the wild che utilizza quella "crittografia" per comunicare con il suo pannello di amministrazione PHP: http://blog.spiderlabs.com/2012/12/the-dexter-malware-getting-your- hands-dirty.html – bsteo

+0

La domanda è, come hai ottenuto quel risultato '$ mustget = 'Kw4SCQ ==''? – Touki

risposta

10
$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

Sono sicuro che si può invertire e creare una funzione, che "cripte" i dati ;-)

+0

Splendida risposta, grazie! Certo che posso. – bsteo

+0

Modulo è tuo amico! – Drasill