(メッセージはありません)
@@ -33,11 +33,11 @@ | ||
33 | 33 | * |
34 | 34 | * @param syn int[] |
35 | 35 | * syndrome |
36 | - * s0,s1,s2, ... s<npar-1> | |
36 | + * s0,s1,s2, ... s<npar-1> | |
37 | 37 | * @return int[][] |
38 | - * null: fail | |
39 | - * [0]: sigma(z) | |
40 | - * [1]: omega(z) | |
38 | + * null: fail | |
39 | + * [0]: sigma(z) | |
40 | + * [1]: omega(z) | |
41 | 41 | */ |
42 | 42 | public int[][] calcSigmaMBM(int[] syn) { |
43 | 43 | int[] sg0 = new int[npar+ 1]; |
@@ -85,12 +85,27 @@ | ||
85 | 85 | return new int[][] {sigma, omega}; |
86 | 86 | } |
87 | 87 | |
88 | + private int[] chienSearch(int length, int start, int wa, int seki) { | |
89 | + for(int i = start; i < length; i++) { | |
90 | + final int z0 = galois.toExp(i); | |
91 | + final int z1 = wa ^ z0; | |
92 | + if(galois.mulExp(z1, i) == seki) { | |
93 | + int idx = galois.toLog(z1); | |
94 | + if(idx <= i || idx >= length) { | |
95 | + return null; | |
96 | + } | |
97 | + return new int[] {z1, z0}; | |
98 | + } | |
99 | + } | |
100 | + return null; | |
101 | + } | |
102 | + | |
88 | 103 | /** |
89 | 104 | * Calculates Error Location(s) |
90 | 105 | * (Chien Search Algorithm) |
91 | 106 | * |
92 | 107 | * @param length int |
93 | - * data length (with parity) | |
108 | + * data length (with parity) | |
94 | 109 | * @param sigma int[] |
95 | 110 | * @return int |
96 | 111 | * null: fail |
@@ -98,33 +113,37 @@ | ||
98 | 113 | */ |
99 | 114 | private int[] chienSearch(int length, int[] sigma) { |
100 | 115 | final int jisu = sigma.length - 1; |
101 | - int[] pos = new int[jisu]; | |
102 | - int last = sigma[1]; | |
116 | + int wa = sigma[1]; | |
117 | + int seki = sigma[jisu]; | |
103 | 118 | if(jisu == 1) { |
104 | - if(galois.toLog(last) >= length) { | |
119 | + if(galois.toLog(wa) >= length) { | |
105 | 120 | return null; |
106 | 121 | } |
107 | - pos[0] = last; | |
108 | - return pos; | |
122 | + return new int[] {wa}; | |
109 | 123 | } |
124 | + if(jisu == 2) { | |
125 | + return chienSearch(length, 0, wa, seki); | |
126 | + } | |
127 | + | |
128 | + int[] pos = new int[jisu]; | |
110 | 129 | int posIdx = jisu - 1; |
111 | 130 | for(int i = 0, z = 255; i < length; i++, z--) { |
112 | - int wz = z; | |
113 | 131 | int wk = 1; |
114 | - for(int j = 1; j <= jisu; j++) { | |
132 | + for(int j = 1, wz = z; j <= jisu; j++, wz = (wz + z) % 255) { | |
115 | 133 | wk ^= galois.mulExp(sigma[j], wz); |
116 | - wz = (wz + z) % 255; | |
117 | 134 | } |
118 | 135 | if(wk == 0) { |
119 | 136 | int pv = galois.toExp(i); |
120 | - last ^= pv; | |
137 | + wa ^= pv; | |
138 | + seki = galois.div(seki, pv); | |
121 | 139 | pos[posIdx--] = pv; |
122 | - if(posIdx == 0) { | |
123 | - int lastIdx = galois.toLog(last); | |
124 | - if(lastIdx <= i || lastIdx >= length) { | |
140 | + if(posIdx == 1) { | |
141 | + int[] pos2 = chienSearch(length, i + 1, wa, seki); | |
142 | + if(pos2 == null) { | |
125 | 143 | return null; |
126 | 144 | } |
127 | - pos[0] = last; | |
145 | + pos[0] = pos2[0]; | |
146 | + pos[1] = pos2[1]; | |
128 | 147 | return pos; |
129 | 148 | } |
130 | 149 | } |
@@ -159,13 +178,13 @@ | ||
159 | 178 | * @param data int[] |
160 | 179 | * input data |
161 | 180 | * @param length int |
162 | - * data length (with parity) | |
181 | + * data length (with parity) | |
163 | 182 | * @param noCorrect boolean |
164 | - * error check only | |
183 | + * error check only | |
165 | 184 | * @return int |
166 | - * 0: has no error | |
167 | - * > 0: # of corrected | |
168 | - * < 0: fail | |
185 | + * 0: has no error | |
186 | + * > 0: # of corrected | |
187 | + * < 0: fail | |
169 | 188 | */ |
170 | 189 | public int decode(int[] data, int length, boolean noCorrect) { |
171 | 190 | if(length < npar || length > 255) { |