Kod: Tümünü seç
private string Decode(byte[] data, ref int offset)
{
byte[] decodedData;
int stringLength = data[offset] | (data[offset + 1] << 8) | (data[offset + 2] << 16) | (data[offset + 3] << 24);
offset += 4;
if (stringLength < 32768) //sanity check
{
decodedData = new byte[stringLength];
uint modWord = 0x0816;
for (int i = 0; i < stringLength; i++)
{
byte encodedByte = data[i + offset];
uint tmpModWord = modWord;
byte decodedByte = 0;
tmpModWord &= 0xff00;
tmpModWord = tmpModWord >> 8;
decodedByte = (byte)(tmpModWord ^ encodedByte);
tmpModWord = encodedByte;
tmpModWord += modWord;
tmpModWord = tmpModWord & 0xffff; //eliminate overflow
tmpModWord = tmpModWord * 0x6081;
tmpModWord = tmpModWord & 0xffff; //eliminate overflow
tmpModWord += 0x1608;
tmpModWord = tmpModWord & 0xffff; //eliminate overflow
modWord = tmpModWord;
decodedData[i] = decodedByte;
}
}
else
{
throw new Exception(String.Format("String too long: {0}", stringLength));
}
offset += stringLength;
//convert the data to a string now and then return it
return System.Text.ASCIIEncoding.ASCII.GetString(decodedData);
}
yukardaki kodu delphi türevi olarak yapılışını sormuş bir arkadaşım. merakıma mucip oldu. Arada bir fırsat buldukça csharp a bakmaya çalışıyorum. işin tuhafı c++ koldarını çevirmekte daha az sıkıntı yaşamıştım.
bir yere kadar getirdim ama tıkandım.