Hallo,
weiß jemand ob/wie man unten stehende Funktion dazu bewegt einen RC4-verschlüsselten String zu entschlüsseln. Das Verschlüsseln damit klappt, aber anders herum nicht - und angeblich soll diese Funktion beides machen. Ich habe in PHP für diesen Zweck ebenfalls eine Funktion, bei der funktioniert das auch, ohne dass man ihr mitteilt, was zu tun ist (s. noch weiter unten). Die macht das zwar nicht in Hex sondern als String, aber eben ohne Anweisung hin und zurück.
Vielen Dank für jede Hilfe...
Trainer
Func rc4($key, $value)
Local $S[256], $i, $j, $c, $t, $x, $y, $output
Local $keyLength = BinaryLen($key), $valLength = BinaryLen($value)
For $i = 0 To 255
$S[$i] = $i
Next
For $i = 0 To 255
$j = Mod($j + $S[$i] + Dec(StringTrimLeft(BinaryMid($key, Mod($i, $keyLength)+1, 1),2)),256)
$t = $S[$i]
$S[$i] = $S[$j]
$S[$j] = $t
Next
For $i = 1 To $valLength
$x = Mod($x+1,256)
$y = Mod($S[$x]+$y,256)
$t = $S[$x]
$S[$x] = $S[$y]
$S[$y] = $t
$j = Mod($S[$x]+$S[$y],256)
$c = BitXOR(Dec(StringTrimLeft(BinaryMid($value, $i, 1),2)), $S[$j])
$output = Binary($output) & Binary('0x' & Hex($c,2))
Next
Return StringTrimLeft(StringLower($output),2)
EndFunc
function rc4($key, $pt) {
$s = array();
for ($i=0; $i<256; $i++) {
$s[$i] = $i;
}
$j = 0;
$x;
for ($i=0; $i<256; $i++) {
$j = ($j + $s[$i] + ord($key[$i % strlen($key)])) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
}
$i = 0;
$j = 0;
$ct = '';
$y;
for ($y=0; $y<strlen($pt); $y++) {
$i = ($i + 1) % 256;
$j = ($j + $s[$i]) % 256;
$x = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $x;
$ct .= $pt[$y] ^ chr($s[($s[$i] + $s[$j]) % 256]);
}
return $ct;
}
Alles anzeigen