Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

Author Topic: Exploiting crc with function  (Read 310 times)

Team dz

• Newbie
• Posts: 1
Exploiting crc with function
« on: March 01, 2023, 09:25:06 am »
Hi  all

Exploiting crc with function
I am working on a algorithm, despite all attempts, I did not reach a result
Does anyone of the members correct me where I am wrong or amend the algorithm for me

I want to modify the code to calculate the value of the checksum

Checksum calculates the sum for a 2-byte checksum

These are some values to show how the function or algorithm is calculated

[/quote]

Code: Pascal  [Select][+][-]
1.  function CRC(Data: AnsiString): UInt16;
2. var
3.  i,j,Sum,f : Integer;
4. begin
5.  Sum := \$0000;
6.  for i := 1 to Length(Data) do
7.
8.
9.  begin
10.
11.   Sum := Sum xor Ord(Data[i]);
12.   for j := 1 to 8 do
13.   begin
14.
15.    f := Sum and \$0001 ;
16.    Sum := Sum shr 1;
17.    if f = 1 then Sum := Sum xor \$FFFF ;
18.    Sum:=sum;
19.   end;
20.
21.  end;
22.  Result := UInt16(Sum);
23. end;
24.

Edit2.Text := IntToHex(CRC(Edit1.Text), 4);

Value  :35E01A00     crc  is  4A16

Quote
4ED8FFFFFFFF
4F4C00000000
8E8C00000001
CE8D00000002
0F4D00000003
4E8F00000004
8F4F00000005
CF4E00000006
0E8E00000007
4E8A00000008
8F4A00000009
CF4B0000000A
0E8B0000000B
4F490000000C
8E890000000D
CE880000000E
0F480000000
4E8000000010
8F4000000011

4A1635E01A00

• Hero Member
• Posts: 12977
Re: Exploiting crc with function
« Reply #1 on: March 01, 2023, 10:51:11 am »
I worked on crc16 some years ago.
See here: https://forum.lazarus.freepascal.org/index.php/topic,38279.msg259533.html#msg259533
Note there is a crc16 in hashes, I believe.

(Silly me, I wrote them - but forgot - and all are there in crc16.pas )
« Last Edit: March 01, 2023, 08:30:31 pm by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

• Hero Member
• Posts: 12977
Re: Exploiting crc with function
« Reply #2 on: March 01, 2023, 08:36:05 pm »