I would need to write in PHP a function that outputs me the same result just like the one in C# bellow.
C#
public void Criptami()
{
szEncryptionKey = 200;
szPlainText = input.text;
StringBuilder szInputStringBuild = new StringBuilder(szPlainText);
StringBuilder szOutStringBuild = new StringBuilder(szPlainText.Length);
char Textch;
for (int iCount = 0; iCount < szPlainText.Length; iCount++)
{
Textch = szInputStringBuild[iCount];
Textch = (char)(Textch ^ szEncryptionKey);
szOutStringBuild.Append(Textch);
}
Debug.Log(szOutStringBuild.ToString());
}
For now I have tried using function that I have found in another dicussion here on Stackoverflow (Encrypt/decrypt with XOR in PHP), but having the same input, the final output is different.
function xor_this($string) {
// Let's define our key here
$key = (200);
// Our plaintext/ciphertext
$text = $string;
// Our output text
$outText = '';
// Iterate through each character
for($i=0; $i<strlen($text); )
{
for($j=0; ($j<strlen($key) && $i<strlen($text)); $j++,$i++)
{
$outText .= $text{$i} ^ $key{$j};
//echo 'i=' . $i . ', ' . 'j=' . $j . ', ' . $outText{$i} . '<br />'; // For debugging
}
}
return $outText;
}
I was given the piece of code in C#, but for what I can gather - eventhough my knowldge of C# is almost non existant - it seems to me it should be operating in exactly the same way?
Thanks a million for your time!
EDIT: I have added input and output values
PHP input: ciao output: QYQ]
C# input: ciao output: «¡©§