blob: 982742142be80730757449f7a13bfd5328bc7f47 (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../qrspec.h"
#include "rsecc_decoder.h"
#define SYMBOL_SIZE (8)
#define symbols ((1 << SYMBOL_SIZE) - 1)
static const int proot = 0x11d; /* stands for x^8+x^4+x^3+x^2+1 (see pp.37 of JIS X0510:2004) */
/* min/max codeword length of ECC, calculated from the specification. */
#define min_length (2)
#define max_length (30)
#define max_generatorSize (max_length)
static unsigned char alpha[symbols + 1];
static unsigned char aindex[symbols + 1];
void RSECC_decoder_init() {
int i, b;
alpha[symbols] = 0;
aindex[0] = symbols;
b = 1;
for(i = 0; i < symbols; i++) {
alpha[i] = (unsigned char)b;
aindex[b] = (unsigned char)i;
b <<= 1;
if(b & (symbols + 1)) {
b ^= proot;
}
b &= symbols;
}
}
int RSECC_decoder_checkSyndrome(int dl, unsigned char *data, int el, unsigned char *ecc)
{
int i, j;
int s;
for(i=0; i<el; i++) {
s = data[0];
for(j=1; j<dl; j++) {
if(s == 0) {
s = data[j];
} else {
s = data[j] ^ alpha[(aindex[s] + i) % symbols];
}
}
for(j=0; j<el; j++) {
if(s == 0) {
s = ecc[j];
} else {
s = ecc[j] ^ alpha[(aindex[s] + i) % symbols];
}
}
if(s != 0) {
return -1;
}
}
return 0;
}
|