ik dien met php een AscII checksum te berekenen op basis van XOR en onderstaande code. Nou weet ik niet hoe XOR werkt (valt uiteraard uit te zoeken, googlelen, zoeken etc..) en weet ik niet in welke taal onderstaande code is geschreven (C++ ??).
2 dingen
- graag wat hulp met t begrijpen van onderstaande code
- hoe werkt XOR in dit onderstaande voorbeeld ?
een checksum dient berekent te worden op basis van bijvoorbeeld onderstaande string:
>STKA001800000300000120000060000060168151010;PW=36393639;ID=00000000;*
De checksum voor die string is: 1A<
Totale string wordt dan:
>STKA001800000300000120000060000060168151010;PW=36393639;ID=00000000;*1A<
(berekend met behulp van een stand alone app AscII checksum calculator)
2 dingen
- graag wat hulp met t begrijpen van onderstaande code
- hoe werkt XOR in dit onderstaande voorbeeld ?
een checksum dient berekent te worden op basis van bijvoorbeeld onderstaande string:
>STKA001800000300000120000060000060168151010;PW=36393639;ID=00000000;*
De checksum voor die string is: 1A<
Totale string wordt dan:
>STKA001800000300000120000060000060168151010;PW=36393639;ID=00000000;*1A<
(berekend met behulp van een stand alone app AscII checksum calculator)
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| /*******************************************************************************
* Function: AppProtocolCalcTAIPChecksum
* Parameters: pszTAIPMsg, checksum
* Returns: Pointer to Checksum Header ;* if found, NULL otherwise.
* Description: This function checks for the presense of the TAIP checksum
* header. If it exists it calculates the checksum and
* places it in the checksum parameter and returns a pointer
* to the checksum header.
* Otherwise it returns NULL without changing checksum.
******************************************************************************/
char* AppProtocolCalcTAIPChecksum(char *pszTAIPMsg, unsigned char *checksum)
{
char *pcEnd;
char *pc;
unsigned char cs;
if((pcEnd = strstr(pszTAIPMsg, ";*")) != NULL) {
pc = pszTAIPMsg; // Start of the checsumed chars.
pcEnd += 2; // Move to the first non-checksumed char.
cs = 0;
while(pc < pcEnd) {
cs ^= *pc;
pc++;
}
*checksum = cs;
return pcEnd-2;
} else {
return NULL;
}
} |