I have the string "0AAE0000463130004144430000", and I need to calculate the two complement checksums of the hexadecimal bytes that make up the string.
The formula for the sample line above
- Summarize the values: 0A + AE + 00 + 00 + 46 + 31 + 30 + 00 + 41 + 44 + 43 + 00 + 00 = 27 (discard overflow)
- Subtract the result from 0x100 = 0xD9
D9 is the correct checksum for this example, but I am having trouble getting two-digit hexadecimal values aligned from a string in C #. My current code is below:
string output = "0AAE0000463130004144430000";
long checksum = 0;
char[] outputBytes = output.TrimStart(':').ToCharArray();
foreach (var outputByte in outputBytes)
{
checksum += Convert.ToInt32(outputByte);
checksum = checksum & 0xFF;
}
checksum = 256 - checksum;
However, this sums up the ASCII values, as far as I can tell, and do it for each individual character.
Crack source
share