Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't locate the difference between my C# encryption function, and my PHP encryption function
    primarykey
    data
    text
    <p>I wrote (what I thought to be) identical encryption functions in PHP and C#. However, encrypting the same string is not producing identical results. I'm no expert in either C# nor PHP so I was hoping someone might be able to spot the difference that for some reason I am not catching here.</p> <p><strong>PHP function:</strong></p> <pre><code>function encrypt($string, $key) { $result = NULL; for($i=0; $i&lt;strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)+ord($keychar)); $result.=$char; } //return $result; return $result; } </code></pre> <p><strong>C# function:</strong></p> <pre><code> public static string encrypt_php_data(string stringToEncrypt, string key) { var result = string.Empty; for (int i = 0; i &lt; stringToEncrypt.Length; i++) { string keychar = phpSubStr_replacement(key, (i % key.Length) - 1); result += (char)(Convert.ToChar(stringToEncrypt.Substring(i, 1)) + Convert.ToChar(keychar)); } return result; } private static string phpSubStr_replacement(string stringToGrab, int startIndex) { if (startIndex &lt; 0) { // Take from end of string return stringToGrab.Substring(stringToGrab.Length + startIndex, 1); } else { // Take from beginning of string return stringToGrab.Substring(startIndex, 1); } } </code></pre> <p>Here are the results of encrypting identical strings:</p> <p>String encrypted: 09/16/2011 15:27:45</p> <p>password used: somekey</p> <pre><code>C# Result: ©¬©¤  «ª©¡ PHP Result: ©¬žž›š—©¤ – Ÿ«ª©¡š </code></pre> <h3>Note:</h3> <p>Not all outputs vary from each other. I cannot understand why some are different, while others produce the same outcome, makes no sense.</p> <p>I look forward to your responses,</p> <p>Evan</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload