| Home Page | Recent Changes | Preferences

# CRC32

CRC32 (Cyclic Redundancy Check) is an algorithm that digests data into a 32-bit checksum. Small changes of the digested data yield large changes of the produced checksum. It is (fundamentally) impossible to retrieve the original data from the calculated checksum.

Checksums have a lot of uses. The implementation below is used in a Jailbreak class that transmits statistics data to a central stats server. The client knows the secret password necessary to authenticate itself with the server; but to keep that password from being sent over the Internet in clear text, the client calculates a checksum over the transmitted stats data and the password. The server, knowing the password as well, can then validate the data and the client's authenticity by calculating the same checksum itself and comparing it to the given one.

(A more sophisticated algorithm would have the server send the client a challenge first that's also digested by the checksum algorithm. That way the server could be sure that the client really is aware of the password and not just copying a prior overheard request.)

## Implementation

The following implementation in UnrealScript has been created by Mychaeel for the Jailbreak mod. Feel free to use and modify.

    var private int CrcTable[256];

    // ============================================================================
    // CrcInit
    //
    // Initializes CrcTable and prepares it for use with Crc.
    // ============================================================================

    final function CrcInit() {

      const CrcPolynomial = 0xedb88320;

      local int CrcValue;
      local int IndexBit;
      local int IndexEntry;

      for (IndexEntry = 0; IndexEntry < 256; IndexEntry++) {
        CrcValue = IndexEntry;

        for (IndexBit = 8; IndexBit > 0; IndexBit--)
          if ((CrcValue & 1) != 0)
            CrcValue = (CrcValue >>> 1) ^ CrcPolynomial;
          else
            CrcValue = CrcValue >>> 1;

        CrcTable[IndexEntry] = CrcValue;
        }
      }

    // ============================================================================
    // Crc
    //
    // Calculates and returns a checksum of the given string. Call CrcInit before.
    // ============================================================================

    final function int Crc(coerce string Text) {

      local int CrcValue;
      local int IndexChar;

      CrcValue = 0xffffffff;

      for (IndexChar = 0; IndexChar < Len(Text); IndexChar++)
        CrcValue = (CrcValue >>> 8) ^ CrcTable[Asc(Mid(Text, IndexChar, 1)) ^ (CrcValue & 0xff)];

      return CrcValue;
      }

## Related Links

- [A Painless Guide to CRC Error Detection Algorithms]
- [Cyclic Redundancy Check (CRC)]

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In