Toon posts:

[php] AscII checksum berekenen op basis van XOR

Pagina: 1
Acties:
  • 98 views sinds 30-01-2008

Verwijderd

Topicstarter
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)

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;
    }
}

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 15-04 22:07

NMe

Quia Ego Sic Dico.

Sorry, maar als je problemen hebt met code die je van Experts Exchange haalt, waarom mail je de maker ervan dan niet? Verder: die code is overduidelijk geschreven in C (het gebruik van char* in plaats van strings is kenmerkend), en wat XOR is en doet kun je prima zelf uitvinden. Wij zijn er in elk geval niet om jou andermans code uit te leggen of om je te leren programmeren. Wat we wel voor je kunnen betekenen is je hulp bieden bij je eigen code, maar daar is hier geen sprake van. Dit topic gaat dan ook op slot.

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Dit topic is gesloten.