-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecc.pas
104 lines (85 loc) · 2.04 KB
/
ecc.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
unit ecc;
interface
uses
ucommon;
const
L1_RAW = 24;
L1_Q = 4;
L1_P = 4;
L2_RAW = (1024 * 2);
L2_Q = (26 * 2 * 2);
L2_P = (43 * 2 * 2);
Procedure encode_L2_Q(Data: PBytesArray);
Procedure encode_L2_P(Data: PBytesArray);
implementation
{$INCLUDE l2sq_table.inc}
Procedure encode_L2_Q(Data: PBytesArray);
var
i, j, PQ, PD, PD_S, PD_P: Integer;
a, b: Word;
begin
// unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P + L2_Q];
PD := 0;
PQ := PD + 4 + L2_RAW + 4 + 8 + L2_P;
// Q := Pointer(LongWord(Data) + 4 + L2_RAW + 4 + 8 + L2_P);
PD_S := PD;
For j := 0 To 26 - 1 do
begin
a := 0;
b := 0;
PD_P := PD_S;
For i := 0 To 43 - 1 do
begin
(* LSB *)
a := a XOR L2sq[i][Data^[PD_P]];
Inc(PD_P);
(* MSB *)
b := b XOR L2sq[i][Data^[PD_P]];
Inc(PD_P, 2 * 44 - 1);
if PD_P >= PD + (4 + L2_RAW + 4 + 8 + L2_P) Then
Dec(PD_P, (4 + L2_RAW + 4 + 8 + L2_P));
end;
Data^[PQ + 0] := a SHR 8;
Move(a, Data^[PQ + 26 * 2], 1);
// Q^[26*2] := a;
Data^[PQ + 1] := b SHR 8;
Move(b, Data^[PQ + 26 * 2 + 1], 1);
// Q^[26*2+1] := b;
Inc(PQ, 2);
Inc(PD_S, 2 * 43);
end;
end;
Procedure encode_L2_P(Data: PBytesArray);
// unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P];
var
i, j, PD, PD_PP, PD_P: Integer;
a, b: Word;
begin
PD := 0;
PD_PP := PD + 4 + L2_RAW + 4 + 8;
// LongWord(P) := PD + 4 + L2_RAW + 4 + 8;
For j := 0 To 43 - 1 do
begin
a := 0;
b := 0;
PD_P := PD;
For i := 19 to 43 - 1 do
begin
(* LSB *)
a := a xor L2sq[i][Data^[PD_P]];
Inc(PD_P);
(* MSB *)
b := b xor L2sq[i][Data^[PD_P]];
Inc(PD_P, 2 * 43 - 1);
end;
Data^[PD_PP + 0] := a SHR 8;
Move(a, Data^[PD_PP + 43 * 2], SizeOf(a));
// P^[43*2] := a;
Data^[PD_PP + 1] := b SHR 8;
Move(b, Data^[PD_PP + 43 * 2 + 1], SizeOf(b));
// P^[43*2+1] := b;
Inc(PD_PP, 2);
Inc(PD, 2);
end;
end;
end.