├── .gitattributes
├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── description.html
├── kotlinc.xml
├── misc.xml
├── modules.xml
├── project-template.xml
├── uiDesigner.xml
├── vcs.xml
└── workspace.xml
├── crccalc.iml
├── license.txt
└── src
└── com
└── crccalc
├── AlgoParams.java
├── Crc16.java
├── Crc32.java
├── Crc64.java
├── Crc8.java
├── CrcCalculator.java
├── CrcHelper.java
└── Main.java
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # Windows shortcuts
18 | *.lnk
19 |
20 | # =========================
21 | # Operating System Files
22 | # =========================
23 |
24 | # OSX
25 | # =========================
26 |
27 | .DS_Store
28 | .AppleDouble
29 | .LSOverride
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear in the root of a volume
35 | .DocumentRevisions-V100
36 | .fseventsd
37 | .Spotlight-V100
38 | .TemporaryItems
39 | .Trashes
40 | .VolumeIcon.icns
41 |
42 | # Directories potentially created on remote AFP share
43 | .AppleDB
44 | .AppleDesktop
45 | Network Trash Folder
46 | Temporary Items
47 | .apdisk
48 | out
49 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | crccalc
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple Java application that includes a class with main()
method
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/project-template.xml:
--------------------------------------------------------------------------------
1 |
2 | IJ_BASE_PACKAGE
3 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
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 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
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 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 | 1459885361385
228 |
229 |
230 | 1459885361385
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 | No facets are configured
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 | 1.8
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 | crccalc
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
--------------------------------------------------------------------------------
/crccalc.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017 Anton Isakov http://crccalc.com
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/src/com/crccalc/AlgoParams.java:
--------------------------------------------------------------------------------
1 | package com.crccalc;
2 |
3 | /**
4 | * Created by anthony on 11.05.2017.
5 | */
6 | public class AlgoParams
7 | {
8 |
9 | public AlgoParams(String name, int hashSize, long poly, long init, boolean refIn, boolean refOut, long xorOut, long check)
10 | {
11 | Name = name;
12 | Check = check;
13 | Init = init;
14 | Poly = poly;
15 | RefIn = refIn;
16 | RefOut = refOut;
17 | XorOut = xorOut;
18 | HashSize = hashSize;
19 | }
20 |
21 | ///
22 | /// This field is not strictly part of the definition, and, in
23 | /// the event of an inconsistency between this field and the other
24 | /// field, the other fields take precedence.This field is a check
25 | /// value that can be used as a weak validator of implementations of
26 | /// the algorithm.The field contains the checksum obtained when the
27 | /// ASCII string "123456789" is fed through the specified algorithm
28 | /// (i.e. 313233... (hexadecimal)).
29 | ///
30 | public long Check;
31 |
32 | ///
33 | /// This is hash size.
34 | ///
35 | public int HashSize;
36 |
37 | ///
38 | /// This parameter specifies the initial value of the register
39 | /// when the algorithm starts.This is the value that is to be assigned
40 | /// to the register in the direct table algorithm. In the table
41 | /// algorithm, we may think of the register always commencing with the
42 | /// value zero, and this value being XORed into the register after the
43 | /// N'th bit iteration. This parameter should be specified as a
44 | /// hexadecimal number.
45 | ///
46 | public long Init;
47 |
48 | ///
49 | /// This is a name given to the algorithm. A string value.
50 | ///
51 | public String Name;
52 |
53 | ///
54 | /// This parameter is the poly. This is a binary value that
55 | /// should be specified as a hexadecimal number.The top bit of the
56 | /// poly should be omitted.For example, if the poly is 10110, you
57 | /// should specify 06. An important aspect of this parameter is that it
58 | /// represents the unreflected poly; the bottom bit of this parameter
59 | /// is always the LSB of the divisor during the division regardless of
60 | /// whether the algorithm being modelled is reflected.
61 | ///
62 | public long Poly;
63 |
64 | ///
65 | /// This is a boolean parameter. If it is FALSE, input bytes are
66 | /// processed with bit 7 being treated as the most significant bit
67 | /// (MSB) and bit 0 being treated as the least significant bit.If this
68 | /// parameter is FALSE, each byte is reflected before being processed.
69 | ///
70 | public boolean RefIn;
71 |
72 | ///
73 | /// This is a boolean parameter. If it is set to FALSE, the
74 | /// final value in the register is fed into the XOROUT stage directly,
75 | /// otherwise, if this parameter is TRUE, the final register value is
76 | /// reflected first.
77 | ///
78 | public boolean RefOut;
79 |
80 | ///
81 | /// This is an W-bit value that should be specified as a
82 | /// hexadecimal number.It is XORed to the final register value (after
83 | /// the REFOUT) stage before the value is returned as the official
84 | /// checksum.
85 | ///
86 | public long XorOut;
87 | }
--------------------------------------------------------------------------------
/src/com/crccalc/Crc16.java:
--------------------------------------------------------------------------------
1 | package com.crccalc;
2 |
3 | /**
4 | * Created by anthony on 15.05.2017.
5 | */
6 | public class Crc16 {
7 | public static AlgoParams Crc16CcittFalse = new AlgoParams("CRC-16/CCITT-FALSE", 16, 0x1021, 0xFFFF, false, false, 0x0, 0x29B1);
8 | public static AlgoParams Crc16Arc = new AlgoParams("CRC-16/ARC", 16, 0x8005, 0x0, true, true, 0x0, 0xBB3D);
9 | public static AlgoParams Crc16AugCcitt = new AlgoParams("CRC-16/AUG-CCITT", 16, 0x1021, 0x1D0F, false, false, 0x0, 0xE5CC);
10 | public static AlgoParams Crc16Buypass = new AlgoParams("CRC-16/BUYPASS", 16, 0x8005, 0x0, false, false, 0x0, 0xFEE8);
11 | public static AlgoParams Crc16Cdma2000 = new AlgoParams("CRC-16/CDMA2000", 16, 0xC867, 0xFFFF, false, false, 0x0, 0x4C06);
12 | public static AlgoParams Crc16Dds110 = new AlgoParams("CRC-16/DDS-110", 16, 0x8005, 0x800D, false, false, 0x0, 0x9ECF);
13 | public static AlgoParams Crc16DectR = new AlgoParams("CRC-16/DECT-R", 16, 0x589, 0x0, false, false, 0x1, 0x7E);
14 | public static AlgoParams Crc16DectX = new AlgoParams("CRC-16/DECT-X", 16, 0x589, 0x0, false, false, 0x0, 0x7F);
15 | public static AlgoParams Crc16Dnp = new AlgoParams("CRC-16/DNP", 16, 0x3D65, 0x0, true, true, 0xFFFF, 0xEA82);
16 | public static AlgoParams Crc16En13757 = new AlgoParams("CRC-16/EN-13757", 16, 0x3D65, 0x0, false, false, 0xFFFF, 0xC2B7);
17 | public static AlgoParams Crc16Genibus = new AlgoParams("CRC-16/GENIBUS", 16, 0x1021, 0xFFFF, false, false, 0xFFFF, 0xD64E);
18 | public static AlgoParams Crc16Maxim = new AlgoParams("CRC-16/MAXIM", 16, 0x8005, 0x0, true, true, 0xFFFF, 0x44C2);
19 | public static AlgoParams Crc16Mcrf4Xx = new AlgoParams("CRC-16/MCRF4XX", 16, 0x1021, 0xFFFF, true, true, 0x0, 0x6F91);
20 | public static AlgoParams Crc16Riello = new AlgoParams("CRC-16/RIELLO", 16, 0x1021, 0xB2AA, true, true, 0x0, 0x63D0);
21 | public static AlgoParams Crc16T10Dif = new AlgoParams("CRC-16/T10-DIF", 16, 0x8BB7, 0x0, false, false, 0x0, 0xD0DB);
22 | public static AlgoParams Crc16Teledisk = new AlgoParams("CRC-16/TELEDISK", 16, 0xA097, 0x0, false, false, 0x0, 0xFB3);
23 | public static AlgoParams Crc16Tms37157 = new AlgoParams("CRC-16/TMS37157", 16, 0x1021, 0x89EC, true, true, 0x0, 0x26B1);
24 | public static AlgoParams Crc16Usb = new AlgoParams("CRC-16/USB", 16, 0x8005, 0xFFFF, true, true, 0xFFFF, 0xB4C8);
25 | public static AlgoParams CrcA = new AlgoParams("CRC-A", 16, 0x1021, 0xc6c6, true, true, 0x0, 0xBF05);
26 | public static AlgoParams Crc16Kermit = new AlgoParams("CRC-16/KERMIT", 16, 0x1021, 0x0, true, true, 0x0, 0x2189);
27 | public static AlgoParams Crc16Modbus = new AlgoParams("CRC-16/MODBUS", 16, 0x8005, 0xFFFF, true, true, 0x0, 0x4B37);
28 | public static AlgoParams Crc16X25 = new AlgoParams("CRC-16/X-25", 16, 0x1021, 0xFFFF, true, true, 0xFFFF, 0x906E);
29 | public static AlgoParams Crc16Xmodem = new AlgoParams("CRC-16/XMODEM", 16, 0x1021, 0x0, false, false, 0x0, 0x31C3);
30 |
31 | public static final AlgoParams[] Params = new AlgoParams[]
32 | {
33 | Crc16CcittFalse,
34 | Crc16Arc,
35 | Crc16AugCcitt,
36 | Crc16Buypass,
37 | Crc16Cdma2000,
38 | Crc16Dds110,
39 | Crc16DectR,
40 | Crc16DectX,
41 | Crc16Dnp,
42 | Crc16En13757,
43 | Crc16Genibus,
44 | Crc16Maxim,
45 | Crc16Mcrf4Xx,
46 | Crc16Riello,
47 | Crc16T10Dif,
48 | Crc16Teledisk,
49 | Crc16Tms37157,
50 | Crc16Usb,
51 | CrcA,
52 | Crc16Kermit,
53 | Crc16Modbus,
54 | Crc16X25,
55 | Crc16Xmodem,
56 | };
57 | }
--------------------------------------------------------------------------------
/src/com/crccalc/Crc32.java:
--------------------------------------------------------------------------------
1 | package com.crccalc;
2 |
3 | /**
4 | * Created by anthony on 15.05.2017.
5 | */
6 | public class Crc32 {
7 | public static AlgoParams Crc32 = new AlgoParams("CRC-32", 32, 0x04C11DB7L, 0xFFFFFFFFL, true, true, 0xFFFFFFFFL, 0xCBF43926L);
8 | public static AlgoParams Crc32Bzip2 = new AlgoParams("CRC-32/BZIP2", 32, 0x04C11DB7L, 0xFFFFFFFFL, false, false, 0xFFFFFFFFL, 0xFC891918L);
9 | public static AlgoParams Crc32C = new AlgoParams("CRC-32C", 32, 0x1EDC6F41L, 0xFFFFFFFFL, true, true, 0xFFFFFFFFL, 0xE3069283L);
10 | public static AlgoParams Crc32D = new AlgoParams("CRC-32D", 32, 0xA833982BL, 0xFFFFFFFFL, true, true, 0xFFFFFFFFL, 0x87315576L);
11 | public static AlgoParams Crc32Jamcrc = new AlgoParams("CRC-32/JAMCRC", 32, 0x04C11DB7L, 0xFFFFFFFFL, true, true, 0x00000000L, 0x340BC6D9L);
12 | public static AlgoParams Crc32Mpeg2 = new AlgoParams("CRC-32/MPEG-2", 32, 0x04C11DB7L, 0xFFFFFFFFL, false, false, 0x00000000L, 0x0376E6E7L);
13 | public static AlgoParams Crc32Posix = new AlgoParams("CRC-32/POSIX", 32, 0x04C11DB7L, 0x00000000L, false, false, 0xFFFFFFFFL, 0x765E7680L);
14 | public static AlgoParams Crc32Q = new AlgoParams("CRC-32Q", 32, 0x814141ABL, 0x00000000L, false, false, 0x00000000L, 0x3010BF7FL);
15 | public static AlgoParams Crc32Xfer = new AlgoParams("CRC-32/XFER", 32, 0x000000AFL, 0x00000000L, false, false, 0x00000000L, 0xBD0BE338L);
16 |
17 | public static final AlgoParams[] Params = new AlgoParams[]{
18 | Crc32, Crc32Bzip2, Crc32C, Crc32D, Crc32Jamcrc, Crc32Mpeg2, Crc32Posix, Crc32Q, Crc32Xfer
19 | };
20 | }
--------------------------------------------------------------------------------
/src/com/crccalc/Crc64.java:
--------------------------------------------------------------------------------
1 | package com.crccalc;
2 |
3 | public class Crc64 {
4 | public static AlgoParams Crc64 = new AlgoParams("CRC-64",64, 0x42F0E1EBA9EA3693L, 0x00000000L, false, false, 0x00000000L, 0x6C40DF5F0B497347L);
5 | public static AlgoParams Crc64We = new AlgoParams("CRC-64/WE", 64, 0x42F0E1EBA9EA3693L, 0xFFFFFFFFFFFFFFFFL, false, false, 0xFFFFFFFFFFFFFFFFL,0x62EC59E3F1A4F00AL);
6 | public static AlgoParams Crc64Xz = new AlgoParams("CRC-64/XZ", 64, 0x42F0E1EBA9EA3693L, 0xFFFFFFFFFFFFFFFFL, true, true, 0xFFFFFFFFFFFFFFFFL,0x995DC9BBDF1939FAL);
7 |
8 |
9 | public static final AlgoParams[] Params = new AlgoParams[]{
10 | Crc64, Crc64We, Crc64Xz
11 | };
12 | }
13 |
--------------------------------------------------------------------------------
/src/com/crccalc/Crc8.java:
--------------------------------------------------------------------------------
1 | package com.crccalc;
2 |
3 | /**
4 | * Created by anthony on 15.05.2017.
5 | */
6 | public class Crc8 {
7 | public static AlgoParams Crc8 = new AlgoParams("CRC-8", 8, 0x7, 0x0, false, false, 0x0, 0xF4);
8 | public static AlgoParams Crc8Cdma2000 = new AlgoParams("CRC-8/CDMA2000", 8, 0x9B, 0xFF, false, false, 0x0, 0xDA);
9 | public static AlgoParams Crc8Darc = new AlgoParams("CRC-8/DARC", 8, 0x39, 0x0, true, true, 0x0, 0x15);
10 | public static AlgoParams Crc8DvbS2 = new AlgoParams("CRC-8/DVB-S2", 8, 0xD5, 0x0, false, false, 0x0, 0xBC);
11 | public static AlgoParams Crc8Ebu = new AlgoParams("CRC-8/EBU", 8, 0x1D, 0xFF, true, true, 0x0, 0x97);
12 | public static AlgoParams Crc8ICode = new AlgoParams("CRC-8/I-CODE", 8, 0x1D, 0xFD, false, false, 0x0, 0x7E);
13 | public static AlgoParams Crc8Itu = new AlgoParams("CRC-8/ITU", 8, 0x7, 0x0, false, false, 0x55, 0xA1);
14 | public static AlgoParams Crc8Maxim = new AlgoParams("CRC-8/MAXIM", 8, 0x31, 0x0, true, true, 0x0, 0xA1);
15 | public static AlgoParams Crc8Rohc = new AlgoParams("CRC-8/ROHC", 8, 0x7, 0xFF, true, true, 0x0, 0xD0);
16 | public static AlgoParams Crc8Wcdma = new AlgoParams("CRC-8/WCDMA", 8, 0x9B, 0x0, true, true, 0x0, 0x25);
17 |
18 | public static final AlgoParams[] Params = new AlgoParams[]{
19 | Crc8, Crc8Cdma2000, Crc8Darc, Crc8DvbS2, Crc8Ebu, Crc8ICode, Crc8Itu, Crc8Maxim, Crc8Rohc, Crc8Wcdma
20 | };
21 | }
--------------------------------------------------------------------------------
/src/com/crccalc/CrcCalculator.java:
--------------------------------------------------------------------------------
1 | package com.crccalc;
2 |
3 | /**
4 | * Created by anthony on 11.05.2017.
5 | */
6 | public class CrcCalculator {
7 |
8 | public AlgoParams Parameters;
9 | public byte HashSize = 8;
10 | private long _mask = 0xFFFFFFFFFFFFFFFFL;
11 | private long[] _table = new long[256];
12 |
13 | public static final byte[] TestBytes = new byte[]{49,50,51,52,53,54,55,56,57};
14 |
15 | CrcCalculator(AlgoParams params)
16 | {
17 | Parameters = params;
18 |
19 | HashSize = (byte) params.HashSize;
20 | if (HashSize < 64)
21 | {
22 | _mask = (1L << HashSize) - 1;
23 | }
24 |
25 | CreateTable();
26 | }
27 |
28 | public long Calc(byte[] data, int offset, int length)
29 | {
30 | long init = Parameters.RefOut ? CrcHelper.ReverseBits(Parameters.Init, HashSize) : Parameters.Init;
31 | long hash = ComputeCrc(init, data, offset, length);
32 | return (hash ^ Parameters.XorOut) & _mask;
33 | }
34 |
35 | private long ComputeCrc(long init, byte[] data, int offset, int length)
36 | {
37 | long crc = init;
38 |
39 | if (Parameters.RefOut)
40 | {
41 | for (int i = offset; i < offset + length; i++)
42 | {
43 | crc = (_table[(int)((crc ^ data[i]) & 0xFF)] ^ (crc >>> 8));
44 | crc &= _mask;
45 | }
46 | }
47 | else
48 | {
49 | int toRight = (HashSize - 8);
50 | toRight = toRight < 0 ? 0 : toRight;
51 | for (int i = offset; i < offset + length; i++)
52 | {
53 | crc = (_table[(int)(((crc >> toRight) ^ data[i]) & 0xFF)] ^ (crc << 8));
54 | crc &= _mask;
55 | }
56 | }
57 |
58 | return crc;
59 | }
60 |
61 | private void CreateTable()
62 | {
63 | for (int i = 0; i < _table.length; i++)
64 | _table[i] = CreateTableEntry(i);
65 | }
66 |
67 | private long CreateTableEntry(int index)
68 | {
69 | long r = (long)index;
70 |
71 | if (Parameters.RefIn)
72 | r = CrcHelper.ReverseBits(r, HashSize);
73 | else if (HashSize > 8)
74 | r <<= (HashSize - 8);
75 |
76 | long lastBit = (1L << (HashSize - 1));
77 |
78 | for (int i = 0; i < 8; i++)
79 | {
80 | if ((r & lastBit) != 0)
81 | r = ((r << 1) ^ Parameters.Poly);
82 | else
83 | r <<= 1;
84 | }
85 |
86 | if (Parameters.RefOut)
87 | r = CrcHelper.ReverseBits(r, HashSize);
88 |
89 | return r & _mask;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/com/crccalc/CrcHelper.java:
--------------------------------------------------------------------------------
1 | package com.crccalc;
2 |
3 | /**
4 | * Created by anthony on 13.05.2017.
5 | */
6 | public class CrcHelper {
7 |
8 | static long ReverseBits(long ul, int valueLength)
9 | {
10 | long newValue = 0;
11 |
12 | for (int i = valueLength - 1; i >= 0; i--)
13 | {
14 | newValue |= (ul & 1) << i;
15 | ul >>= 1;
16 | }
17 |
18 | return newValue;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/com/crccalc/Main.java:
--------------------------------------------------------------------------------
1 | package com.crccalc;
2 |
3 | import static java.lang.System.out;
4 |
5 | public class Main {
6 |
7 | public static void main(String[] args) {
8 | boolean allRight = true;
9 |
10 | out.println("Checking CRC-8...");
11 | allRight &= Check(Crc8.Params);
12 |
13 | out.println("Checking CRC-16...");
14 | allRight &= Check(Crc16.Params);
15 |
16 | out.println("Checking CRC-32...");
17 | allRight &= Check(Crc32.Params);
18 |
19 | out.println("Checking CRC-64...");
20 | allRight &= Check(Crc64.Params);
21 |
22 | if (allRight)
23 | out.println("All right!");
24 | }
25 |
26 | private static boolean Check(AlgoParams[] params)
27 | {
28 | out.println(params.length + " algos");
29 | boolean allRight = true;
30 | for (int i = 0; i < params.length; i++) {
31 | CrcCalculator calculator = new CrcCalculator(params[i]);
32 | long result = calculator.Calc(CrcCalculator.TestBytes, 0, CrcCalculator.TestBytes.length);
33 | if (result != calculator.Parameters.Check){
34 | out.println(calculator.Parameters.Name + " - BAD ALGO!!! " + Long.toHexString(result).toUpperCase());
35 | allRight = false;
36 | }
37 | }
38 | out.println("done");
39 | out.println();
40 | return allRight;
41 | }
42 | }
--------------------------------------------------------------------------------