29.02.2004, 21:30
Visual Basic code:
Translated by CAHEK7
C# Code:
Translated by CAHEK7
Код:
Public Sub ScriptCrypt(ByRef Script() As Byte, ByVal Key As Long)
Dim Tmp As Double
Dim i As Long
Dim TmpLng As Long
Tmp = Key
For i = 0 To UBound(Script)
Tmp = Tmp * 214013 + 2531011
'-------------------------------------------------
Do While Tmp > 2199023255552#
Tmp = Tmp - 2199023255552#
Loop
Do While Tmp > 274877906944#
Tmp = Tmp - 274877906944#
Loop
Do While Tmp > 34359738368#
Tmp = Tmp - 34359738368#
Loop
Do While Tmp > 4294967296#
Tmp = Tmp - 4294967296#
Loop
' Especially to convert Double to DWORD
' you can change number of cycles
' to change up execution speed
'-------------------------------------------------
TmpLng = CLng(Int(Tmp / 65536))
TmpLng = TmpLng Mod 256
Script(i) = Script(i) Xor CByte(TmpLng)
Next
End Sub
C# Code:
Код:
public string ReadCodedString()
{
byte[] coded = new byte[DataSize - 4]; // sizeof(coded string) - sizeof(key)
char[] decoded = new char[coded.Length];
uint uKey;
// Read
uKey = orStream.ReadUInt32(); // KEY
coded = orStream.ReadBytes(coded.Length); // Coded string
// Decode string
for(int i = 0; i < coded.Length; i++)
{
uKey = uKey * 214013 + 2531011;
decoded[i] = Convert.ToChar(coded[i] ^ Convert.ToByte(uKey / 65536 % 256));
}
return new string(decoded, 0, decoded.Length );
}