Home All Groups Group Topic Archive Search About

LRC Calculation algorithm

Author
9 Jan 2006 11:12 AM
Sankalp
Does anyone know how to calculate Longitudinal Redundancy Check(LRC) in
VB.NET?
I am trying to send Visa-II formatted even parity message to a credit
card processor and am not sure how to calculate the LRC which needs to
be appended to the message.

Any pointers would be most helpful.
Thanks in advance.
Sankalp

Author
9 Jan 2006 11:39 AM
AMercer
> Does anyone know how to calculate Longitudinal Redundancy Check(LRC) in
> VB.NET?

I believe that the lrc byte is just the xor of all the data bytes.
Author
9 Jan 2006 11:56 AM
Sankalp
Here is the code that I am using:
        GenerateMessageETX() - This function returns the credit card
data and the ETX chanracter in the string format.
Then I create an HTTPWebRequest to the credit card payment gateway.


        Dim message As String = pageData

        Dim j As Integer

        Dim LRC As Byte = "0"

        For j = 0 To message.Length - 1
            Dim chr As Char = message.Substring(j, 1)
            LRC = LRC Xor Convert.ToByte(chr)
        Next

Is this the LRC value or do i need to do something else.

Please guide-have been stuck in this for some time now.

Sankalp
Author
9 Jan 2006 3:52 PM
AMercer
"Sankalp" wrote:

>         Dim message As String = pageData
>         Dim j As Integer
>         Dim LRC As Byte = "0"
>         For j = 0 To message.Length - 1
>             Dim chr As Char = message.Substring(j, 1)
>             LRC = LRC Xor Convert.ToByte(chr)
>         Next

I don't like this:
   Dim LRC As Byte = "0"

It probably gives a compiler error.  I would code like this:

      Dim message As String = pageData
      Dim lrc As Integer = 0
      For j As Integer = 0 To message.Length - 1
        lrc = lrc Xor AscW(message.Chars(j))
      Next

At this point, my guess is that you should transmit this string:
   message & Chr(lrc)
It is your pageData string with one lrc byte appended.
Author
9 Jan 2006 8:13 PM
Sankalp
Thanks A, tried this but doesnt work. Now I am beginning to doubt the
servers as well. They have given us 2 servers to test with one being
the backup server. But, both the servers are returning different
responses to the same message. I guess i will have to verify this with
the company. Thanks for your help again :-)

Sankalp