Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

CRC32 Frustration

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

  • CRC32 Frustration

    Hello all!

    Pardon my frustration but I'm quite displeased with my lack of programming understanding. My goal is to write an efficient, modularized function that returns the 32bit CRC for the file passed to it.

    I've attempted to view other programmer's coding in hopes of better understanding what I'm doing but I've reached no conclusion there. I then attempted to alter preexisting code to do what I wanted; but once again, things turned nasty. The most basic of my problems is that I want the ability to do this check; but, I don't understand what I'm checking or how to check it.

    I've been using Randall L. Glass' source to try to backtrack what he's doing; but, I don't know assembly and his code doesn’t produce output quite the way I like. I’d like to throw the lines out:

    Code:
    FileCRC$ = CRC32(FCheck$)
    IF FileCRC$<>InternalCRC$ THEN
    …
    ...and then run with the function's return; but, I can't figure out a clean way of doing this. Well, I’m quite frustrated with this obstacle and I’ll place the program on the backburners for a little while and hope you guys can throw some suggestions or code my way. Many thanks.

    Don Ewald
    [email protected]
    Donnie Ewald
    [email protected]

  • #2
    Sorry if I'm being dense, but I'm not clear about what you're looking for. Non-asm source code for a CRC32 routine? Do you want to understand what a CRC is and how it is calculated? Or do you want a reliable "black box" function that returns a standard CRC32 value and you don't care what's under the hood, or...?

    -- Eric

    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>

    "Not my circus, not my monkeys."

    Comment


    • #3
      Hello Eric!

      Many thanks for the quick reply. I’m assuming since you threw out some questions, that you may be able to help—I sure hope so!

      Non-asm source code for a CRC32 routine? Do you want to understand what a CRC is and how it is calculated?
      In the long run this would be best and most beneficial for me. Though read a little further.

      Or do you want a reliable "black box" function that returns a standard CRC32 value and you don't care what's under the hood, or...?
      I hate to say it; but right now, this would be great! I’d rather see fruition to the remainder of the program then devote my energy to comprehending this. I’d rather have the program up and running and then take my leisurely time in figuring out how CRC works sometime in the future.

      What do you think? Is it something you’d be able to program for me? Not to be too greedy; but, if you can program it in straight PowerBasic, can you include comments and such so I try to figure out the algorithm? Hey, many thanks for whatever assistance you can provide.

      Don Ewald
      mailto:[email protected][email protected]</A>
      Donnie Ewald
      [email protected]

      Comment


      • #4
        Don --

        > I hate to say it; but right now, this would be great!

        Whew! 'Cause, even though I've used them for years, I have no idea whatsoever how they work. And even though I usually enjoy the "under the hood" stuff I have absolutely no desire to know. I tried to follow the logic once and my brain started to scorch. So I've always treated them like a "black box" and as long as the function produces the same results as every other CRC32 generator (Zmodem, etc.) then everything's right with the world.

        Personally, in my PB/DOS programs I use a CRC32 function in an OBJ file that I got from a commercial library years ago. I $LINK it to my programs and never worry about how it works any more than I worry about how the COS function works.

        I can tell you a couple of things, for the day you decide to figure them out… Generally speaking, there are two types of CRC32 functions. The first type is "table based". They involve a long list of numeric values that the function uses in its calculations. Then there are non-table-based functions. They are 100% algorithm-based - usually a relatively small loop -- and they are usually significantly slower than table-based functions, but they are also much smaller, code-wise. And if you want to understand the concept behind CRCs, non-table-based functions are the ones you want to study.

        Second, I discovered a neat trick for determining whether or not a CRC correctly matches a string of bytes. If you calculate the CRC32 for a string, you get a 32-bit (4-byte) CRC string, right? If you add the CRC string to the original string and calculate the CRC of that string, the resulting CRC is always zero, i.e. STRING$(4,0). So you can check something like a file (or a Zmodem block) very easily by calculating the CRC of the string including its CRC (which is presumably the last 4 bytes of the string) and checking for zero.

        As far as source code goes, have you searched this BBS? I just did a quick search of All Open Forums for "CRC" and found several complete PowerBASIC functions. If you need help modifying one of those (to return a LONG instead of a string, or whatever), let me know.

        HTH.

        -- Eric

        ------------------
        Perfect Sync: Perfect Sync Development Tools
        Email: mailto:[email protected][email protected]</A>



        [This message has been edited by Eric Pearson (edited March 09, 2000).]
        "Not my circus, not my monkeys."

        Comment

        Working...
        X