From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 31-OCT-1991 02:22:14.37
To:	ARISIA::EVERHART
CC:	
Subj:	Re: Need CRC routine

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.115)
	 id AA18713; Thu, 31 Oct 91 02:06:29 EST
Received: From DANPOST.UNI-C.DK by CRVAX.SRI.COM with TCP; Wed, 30 OCT 91 12:58:24 PST
Received: from vms2.uni-c.dk by danpost.uni-c.dk (5.65/1.34)
	id AA20756; Wed, 30 Oct 91 20:57:39 GMT
Date: Wed, 30 Oct 91 21:57 +0200
From: ISIS08@ecostat.aau.dk
Subject: Re: Need CRC routine
To: TURGUT@FRORS12.earn, INFO-VAX@SRI.COM
Message-Id: <F173ED9CA23F00768B@vms2.uni-c.dk>
X-Envelope-To: TURGUT@FRORS12.earn, INFO-VAX@SRI.COM
X-Vms-To: UNIL63::IN%"TURGUT@FRORS12.earn"
X-Vms-Cc: IN::"INFO-VAX@SRI.COM"

> Hello. For a programming task, I need a copy of the CRC calculation
> routine of VMS. I basically need to write a routine that would calculate
> the CRC of a file in a manner compatible with VMS.  Thanks in advance, -turgut

For some reason I once made such a piece of code (I do not remember why
anymore). It is a straigthforward implementation in C of the algorithm
in VAX Architecture Reference Manual.

Note: There can be used several different CRC polynomiums, but my program
has one of them hardcoded, but it should be easy to change it.

#include <stdio.h>
#include <descrip.h>
#include <ssdef.h>

void lib$crc_table();
int lib$crc();

#define step 4
#define limit 2
#define index 1

int softcrc(int crctbl[16],int init,char *tststr)
{
   register char *s;
   register int tmp,tmp2,i;
   s = tststr;
   tmp = init;
   while (*s)
      {
         tmp = tmp^((int)*s);
         for (i=0;i<limit;i++)
            {
               tmp2 = tmp>>step;
               tmp2 = tmp2^crctbl[(tmp-(tmp2<<step))*index];
               tmp = tmp2;
            };
         s++;
      };
   return tmp;
};

#define tststr "This is a stupid test-string choosen random"
int poly = 0x0000A001;
int init = 0x00000000;
int crctbl[16];

main()
{
   $DESCRIPTOR(tstdes,tststr);
   lib$crc_table(&poly,&crctbl);
   printf("CRC of >>%s<< is  %d\n",tststr,lib$crc(&crctbl,&init,&tstdes));
   printf("soft-CRC of >>%s<< is  %d\n",tststr,softcrc(crctbl,init,tststr));
   return SS$_NORMAL;
};

The code for LIB$CRC_TABLE is printed in the RTL-manual (FORTRAN).

                                                          Arne Vajhxj

Arne Vajhxj                             Internet: ISIS08@ECOSTAT.AAU.DK
Institute of Economics and Statistics   PSI:      DATAPAX.23830211371400::ISIS08
Aarhus University
Denmark


