The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


LRC - Perl interface for longitudinal redundancy check generation


    use String::LRC;
    $lrc = lrc("string to get lrc of");


The Longitudinal Redundancy Check (LRC) is a one byte character, commonly used as a byte-field in data transmission over analog systems.

Most commonly, in STX-ETX bounded strings sent in financial protocols. Following some previous experience with such protocols, I wrote an LRC function in perl and later decided to re-write in C for efficiency. The result is this module String::LRC, which generates this aforementioned byte.


    use String::LRC;
    $lrc = lrc("string to get lrc of");

  Commonly used in financial protocols as follows with ETX (ASCII 03)
  appended to LRC sum and packets after the STX (ASCII 02), payload,
  and ETX chars.  

    use String::LRC;
    $outboundString = chr(02) . $outboundString . chr(03)
                        . lrc($outboundString . chr(03));

You may also use String::LRC to get the LRC result of a file, following Soenke J. Peters' example for CRC32. However, LRCs are really best used for line-by-line parity.

    use String::LRC;
    open(TESTFILE, "/path/to/test.file");
    $lrc = lrc(*TESTFILE);

A init value may also been supplied in the above example.


Ralph Padron <>

If you have any requests or bugs, send email to the above address (no spam please).


License to use this module/library and make use of in derivative works is is granted to all, freely, provided that this module is identified as "derived from R Padron" and notice of other contributors be provided in any material referencing or mentioning this module. The author makes no representations of possessing full or partial copyright to the LRC code nor the algorythyms used in this module, as said is either public knowledge or inspired by multiple sources.

LRC algorithms taken from combination of sources: 1. Public Specifications, EIS 1081, San Francisco, CA: Visa, 1999

        2. QWEST Communications, Inc. Tech Publication 77359, 
           Module 5, Issue 1, October 2001. pg 36.

        3. Tanenbaum, A. S., Computer Networks,  3rd ed.  
           pp. 186-190Amsterdam, The Netherlands: Vrije Univ., 1996.

The module is inspired by the previous uses the author has had for the LRC generation algorythm; Inspiration for and partial code snippets for initial value and lrc generation of file data provided from Soenke J. Peters' String::CRC32.

The author makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided "as is" without express or implied warranty of any kind.

These notices must be retained in any copies of any part of this documentation and/or software.


String::CRC, String::CRC32, Device::SerialPort, Device::Modem.