home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / hacking / phreak_utils_pc / chksum.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-04-01  |  850 b   |  38 lines

  1. uses hexout;
  2. function getchecksum(fn:string):longint;
  3. type buftype = array[1..32000] of byte;
  4. var p, sum, bsum   :longint;
  5.     fs             :longint;
  6.     toggle         :boolean;
  7.     br,x           :word;
  8.     buf            :^buftype;
  9.     f              :file;
  10. begin
  11.   sum:=1000000;
  12.   bsum:=0;
  13.   toggle:=true;
  14.   assign(f,fn);
  15.   reset(f,1);
  16.   fs:=filesize(f);
  17.   p:=0;
  18.   new(buf);
  19.   repeat
  20.     write('.');
  21.     blockread(f,buf^,sizeof(buf^),br);
  22.     for x:=1 to br do begin
  23.       inc(p);
  24.       bsum:=bsum+buf^[x];
  25.       if toggle then sum:=sum+(buf^[x]*p) else sum:=sum-(buf^[x]*p);
  26.       {toggle:=not(toggle);}
  27.     end;
  28.   until br<>sizeof(buf^);
  29.   close(f);
  30.   dispose(buf);
  31.   getchecksum:=sum+bsum+p;
  32. end;
  33.  
  34. begin
  35.   write('Checking integrity of ',paramstr(1));
  36.   writeln(hexl(getchecksum(paramstr(1))),'h');
  37. end.
  38.