100825/tex/pas100325hashchecksumall.pas

{ (c) David Vajda }
{ 10/03/25 }
{ Pascal Hash Excersize Program }

program pashash(input,output);

    { hier musste ich mir ein wenig wieder ins gedaechtnis rufen }
    { const, type, var ... das ist die richtige art und weise, variablen, ... zu definieren}
const
    tMinIndex = 1;
    tMaxIndex = 10;
type
    tIndex = tMinIndex .. tMaxIndex;
    tFeld = array [tIndex] of ShortInt;
var
    X: tFeld = (2, 87, 16, 41, 76, 65, 33, 91, 7, 32);
    i: tIndex;
    m: ShortInt;
    b: ShortInt;

function Adler32 (X: tFeld; n: tIndex; m: Integer): Integer;
var
    i: tIndex;
    s1: Integer = 1;
    s2: Integer = 0;
begin
    for i := tMinIndex to tMaxIndex do
    begin
        s1 := (s1 + X[i]) mod m;
        s2 := (s2 + s1) mod m;
    end;
    writeln (s1,s2);
    Adler32 := s2 * 256 + s1;
end;

function pashash (X: tFeld; n: tIndex; m: ShortInt; b: ShortInt): ShortInt;
var
    i: tIndex;
    y: ShortInt = 0;
begin
    for i := tMinIndex to tMaxIndex do
    begin
        y := (b * X[i] + y) mod m;
    end;
    pashash := y;
end;

begin
    writeln ('(c) David Vajda');
    writeln ('10/03/25');
    writeln ('Pascal Hash Excersize Program');

    write ('X = (');
    for i := tMinIndex to tMaxIndex do
    begin
        write (X[i], ', ')
    end;
    writeln (X[i], ')');
    writeln ('base=64,m=97,hashval=', pashash(X,tMaxIndex,97,64));
    writeln ('base=100,m=97,hashval=', pashash(X,tMaxIndex,97,100));
    writeln ('base=256,m=251,adler-32-checksum-val=', Adler32(X,tMaxIndex,251));
end.