heb de volgende functie
ik wil deze graag omzetten naar c#. als ik dit probeer
het probleem is dat hij nu niet bij het eerste karakter begint. als ik in vs2005 debug krijg ik alles goed gedecrypt alleen begint hij niet bij het eerste karakter. en dan crasht hij vervolgens op de 2e mid functie. ik heb al geprobeerd om de for loop bij 0 te laten beginnen, maar ik zie iets over het hoofd want ik krijg het niet goed. of bij het eerste karakter of bij het laatste gaat het fout. wat zie ik over het hoofd?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| Function XORDecryption(CodeKey, DataIn)
Dim lonDataPtr
Dim strDataOut
Dim intXOrValue1
Dim intXOrValue2
For lonDataPtr = 1 To (Len(DataIn) / 2)
'The first value to be XOr-ed comes from the data to be encrypted
intXOrValue1 = ("&H" & (Mid(DataIn, (2 * lonDataPtr) - 1, 2)))
'The second value comes from the code key
intXOrValue2 = Asc(Mid(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))
strDataOut = strDataOut & Chr(intXOrValue1 Xor intXOrValue2)
Next
XORDecryption = strDataOut
End Function |
ik wil deze graag omzetten naar c#. als ik dit probeer
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| public string DeCrypt(string CodeKey, string DataIn)
{
int lonDataPtr;
string strDataOut="";
int intXOrValue1,intXOrValue2;
for (lonDataPtr = 1; lonDataPtr < ((DataIn.Length) / 2); lonDataPtr++)
{ //'The first value to be XOr-ed comes from the data to be encrypted
intXOrValue1 = Convert.ToInt32((((Mid(DataIn, (2 * lonDataPtr), 2)))),16);
//intXOrValue1 = ("&H" + (Mid(DataIn, (2 * lonDataPtr) - 1, 2)));
//'The second value comes from the code key
intXOrValue2 = Asc(Mid(CodeKey, ((lonDataPtr % (CodeKey.Length))+ 1), 1));
strDataOut = strDataOut + Chr(intXOrValue1 ^ intXOrValue2);
}
return strDataOut;
} |
het probleem is dat hij nu niet bij het eerste karakter begint. als ik in vs2005 debug krijg ik alles goed gedecrypt alleen begint hij niet bij het eerste karakter. en dan crasht hij vervolgens op de 2e mid functie. ik heb al geprobeerd om de for loop bij 0 te laten beginnen, maar ik zie iets over het hoofd want ik krijg het niet goed. of bij het eerste karakter of bij het laatste gaat het fout. wat zie ik over het hoofd?
Werken is gezond, laat het daarom over aan de zieken!