-
Notifications
You must be signed in to change notification settings - Fork 2
/
CALC.PAS
81 lines (77 loc) · 1.29 KB
/
CALC.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var
S : string;
CRC : word;
AC : word;
count : longint;
procedure WriteCRC( CRC : word );
const
H : string[16]='0123456789ABCDEF';
begin
writeln( H[CRC div $1000+1], H[((CRC and $F00) shr 8)+1],
H[((CRC and $F0) shr 4)+1], H[CRC mod $10+1] );
end;
function CalcCRC( S : string ) : word;
var
CRC : word;
i : word;
c : char;
begin
CRC:=$0000;
for i:=1 to length(S) do begin
c:=S[i];
asm
mov bl, &c
mov bh, 8
@@1:
shl bl, 1
mov ax, CRC
rcl ax, 1
jnc @@2
xor ax, $8408
@@2:
mov CRC, ax
dec bh
jnz @@1
end;
{
asm
cbw
xchg al, ah
mov dx, CRC
xor dx, ax
mov cx, 8
@@1:
mov bx, dx
shl dx, 1
and bx, $8000
jz @@2
xor dx, $1021
@@2:
loop @@1
mov CRC, dx
end;
}
end;
CalcCRC:=CRC;
end;
procedure Search( var S : string; index : word );
var
i : char;
begin
if index<=length(S) then begin
for i:='A' to chr($7F) do begin
S[Index]:=i;
CRC:=CalcCRC( S );
if CRC=AC then begin writeln('<', S, '>'); inc(count); end;
Search( S, index+1);
end;
end;
end;
begin
AC:= CalcCRC( 'DR0P' );
WriteCRC( AC );
readln;
S:=' ';
Search( S, 1 );
writeln( count );
end.