Announcement

Collapse
No announcement yet.

String CRC

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • String CRC

    Hello

    Im looking for an .obj to get a checksum value of a string.
    I want to $link it to my main and just feed it a string and get a return checksum value for that string.

    Im using PB/DOS 3.5

    I have looked through the forums and found a few samples but unfortunately im not skilled enough to understand them.
    I was calling an .obj in QB with success, but it doesnt work in PB.

    Thanks for any help
    [email protected]


    ------------------




    [This message has been edited by Walter VanDerwall (edited May 24, 2005).]

  • #2
    Exactly what are you trying to do? A CRC (Cycle Redundancy Check)
    is designed to ensure that a sequence of bytes (words, or double-
    words) is not accidently modified or corrupted. You start with a
    CRC, and if you later create another CRC and it does not match the
    original, you know that some minor error or change has occurred.

    I say "monor", because there are chance changes that can occur that
    will cause the two CRCs to still match, though the contents are
    different. So the larger the CRC value, the less change that the
    error will go undetected. For this reason CRC32 is generally more
    dependable than CRC16.

    Unless you need to use a standard CRC generator, it is very easy
    to roll your own. Start with a variable set to zero, then as you
    read each byte, word, or dword from as string, rotate the contents
    of the variable left or right by one and XOR it with the byte,
    word, or dword you just read. The XOR operator has the unique
    property of not destroying or losing any bits in the first or
    second parameters, merely flipping bits according to the content
    of both. The variable mentioned receives each change, and is your
    CRC value when it has processed the whole string.

    ------------------
    Old Navy Chief, Systems Engineer, Systems Analyst, now semi-retired

    Comment


    • #3
      In the past in QuickBasic I made a call to a checksum.obj file. (its a Probas7 communication routine)
      that calculated a checksum value for a string.

      Call checksum(a$, num%)
      a$=string to calculate
      num%=return value

      That .obj, when called in PowerBasic, does not work.
      So Im looking for a .obj or some code that will do the same thing but in PB.

      Thanks again

      ------------------


      [This message has been edited by Walter VanDerwall (edited May 24, 2005).]

      Comment


      • #4
        Simple approach to doing a CRC on a string. Note that this is
        just one method designed to generate a CRC. There are more
        sophisticated methods used elsewhere. But if this is just for
        your use, you can make it work any way that you want.

        FUNCTION StrCRC(SomeString AS STRING) AS DWORD
        LOCAL Temp as DWORD, a AS DWORD
        a = (LEN(SomeString) - 1) MOD 4 + 1
        CASE 2
        Temp = ASC(SomeString)
        CASE 3
        Temp = CVWRD(SomeString)
        CASE 4
        Temp = CVWRD(SomeString,2)
        ROTATE LEFT Temp, 8
        Temp = Temp XOR ASC(SomeString)
        END SELECT
        FOR a = a TO LEN(SomeString) STEP 4
        ROTATE LEFT Temp, 1
        Temp = Temp XOR CVDWD(SomeString,a)
        NEXT
        FUNCTION = Temp
        END FUNCTION

        ------------------
        Old Navy Chief, Systems Engineer, Systems Analyst, now semi-retired

        Comment


        • #5
          > was calling an .obj in QB with success, but it doesnt work in PB.

          Strings are totally incompatible between QB and PB. No "obj" file designed for one will work with the other if it uses a string parameter. (And no doubt other parameters, but I don't know enough about those to say for sure).

          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X