SUBROUTINE CF.CALC.LRC(t.message,lrc) * * Application: * Subroutine to calculate longtitudinal redundany check for a string * representing an APACS credit card transaction X/Y/Z message (the * final result of XORing the 7-bit characters comprising the * transaction, the same algorithm working for both transaction messages * sent and acknowledgements received. * * Limitations: * Will only work on platforms which carry raw control characters in * data without substitution or conversion. Users may encounter spurious * errors in instances where the transaction checksum evaluates to exactly * 255 (hex FF) - traditionally the segment mark/item mark character and * used as the internal string terminator on many platforms. Could also * be vastly more efficient if using the native XOR function available on * some platforms. * * Used in conjunction with credit card terminal automation programs. * * t.message: transaction * lrc : resultant LRC check character * -1 = STX missing * -2 = ETX missing * * ======================================================================== * * Conditions of use: * This source code is the property and copyright of Gulraj Rijhwani and * Courtfields Limited. Specific licence is granted to copy and use this * program source, in accordance with the terms and conditions laid out * following. For the purposes of these terms and conditions the term * "developer" is defined to be the individual or company employing the * author incorporating use of this source. Any use of this source code is * deemed to be full and unreserved acceptance of these stated terms. * * 1) All instances of this source code must carry all attached * annotations and comments including, but not limited to, these * these conditions of use in their entirety. * 2) The developer may not alter the program source in any way, without * first obtaining the express written consent of duly authorised * company officers of Courtfields Limited, or its successors. * 3) This source code may not be included in whole or in part in any * proprietary program suite except as a separately compiled module * in wholly unmodified form. Any installed object code must be * accompanied by the original source code at all times. * 4) In the event of any breach of these terms and conditions the * developer shall be liable for an annual usage charge of 200 pounds * sterling for every end user terminal or session using or having * access to use the resulting executable code. * 5) Gulraj Rijhwani and Courtfields Limited make no warranties for * the fitness of this source code, and may not be held liable * for any failure to fulfil the expectations or requirements of * the developer. * * ======================================================================== * lrc = -1; * Transaction incomplete - no STX * IF t.message[1,1] = CHAR(2) THEN * lrc = -2; * Transaction incomplete - no ETX * IF t.message[LEN(t.message),1] = CHAR(3) THEN * * Curiously the LRC check skips the initial STX character (so so can we), * but includes the terminating ETX. Since we know the last character * will always be ETX and the LRC algortihm is order independent we can * pre-initialise the final result and skip the final character XOR * iteration. * no.of.chars = LEN(t.message) - 1 lrc = 3 * FOR c.ptr=2 TO no.of.chars * t.char = SEQ(t.message[c.ptr,1]) b=1 old.lrc = lrc lrc = 0 * * This loop performs the actual XOR * FOR bit.count=1 TO 7 b2 = b + b lrc = lrc + REM(old.lrc-REM(old.lrc,b) + t.char-REM(t.char,b),b2) b = b2 NEXT bit.count * NEXT c.ptr * lrc = CHAR(lrc) ;* And convert to ASCII * END * END * RETURN