-
Notifications
You must be signed in to change notification settings - Fork 7
QPacket Checksum Algorithm
zeroKilo edited this page Nov 10, 2019
·
4 revisions
this checksum algorithm uses the key from yeti.ini in its calculation
`
public static readonly string keyCheckSum = "8dtRv2oj";
private byte CalcChecksum(byte[] Data)
{
int[] Buf = new int[Data.Length >> 2];
Buffer.BlockCopy(Data, 0, Buf, 0, Buf.Length << 2);
byte[] Sum = new byte[4];
Buffer.BlockCopy(new long[] { Buf.Sum(x => (long)x) }, 0, Sum, 0, 4);
int Checksum = (byte)Encoding.ASCII.GetBytes(keyCheckSum).Sum(b => b);
if ((Data.Length & 3) != 0)
Checksum += Data.Skip(Data.Length & ~3).Sum(b => b);
return (byte)(Checksum + Sum.Sum(b => b));
}`