Note that there are some explanatory texts on larger screens.

plurals
  1. POc# Sagepay XOR encryption
    primarykey
    data
    text
    <p>I am trying to write the xor encryption in C# as sagepay encryption is only documented in VB.</p> <p>the vb code is:</p> <pre><code>Public Shared Function simpleXor(ByVal strIn As String, ByVal strKey As String) As String Dim iInIndex As Integer Dim iKeyIndex As Integer Dim strReturn As String If Len(strIn) = 0 Or Len(strKey) = 0 Then simpleXor = "" Exit Function End If iInIndex = 1 iKeyIndex = 1 strReturn = "" '** Step through the plain text source XORing the character at each point with the next character in the key ** '** Loop through the key characters as necessary ** Do While iInIndex &lt;= Len(strIn) strReturn = strReturn &amp; Chr(Asc(Mid(strIn, iInIndex, 1)) Xor Asc(Mid(strKey, iKeyIndex, 1))) iInIndex = iInIndex + 1 If iKeyIndex = Len(strKey) Then iKeyIndex = 0 iKeyIndex = iKeyIndex + 1 Loop simpleXor = strReturn End Function </code></pre> <p>So far I have converted this to </p> <pre><code> public static String SimpleXOR(String strIn, String strKey) { Int32 iInIndex, iKeyIndex; String strReturn; iInIndex = 1; iKeyIndex = 1; strReturn = ""; while (iInIndex &lt;= strIn.Length) { strReturn = strReturn &amp; Strings.Chr(Strings.Asc(Strings.Mid(strIn, iInIndex, 1)) ^ Strings.Asc(Strings.Mid(strKey, iKeyIndex, 1))); iInIndex = iInIndex + 1; if (iKeyIndex == strKey.Length) iKeyIndex = 0; iKeyIndex = iKeyIndex + 1; } } </code></pre> <p>The problem is I didn't understand what this line is doing</p> <pre><code>strReturn = strReturn &amp; Chr(Asc(Mid(strIn, iInIndex, 1)) Xor Asc(Mid(strKey, iKeyIndex, 1))) </code></pre> <p>so I ran it through a vb to c# converter and got the above. But it clearly is not valid c# code as far as I am aware.</p> <p>Can anyone help?</p>
    singulars
    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.
    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