Crc64Helper.java

1
package com.jsql.util.bruter;
2
3
/*******************************************************************************
4
 * Copyright (c) 2009, 2012 Mountainminds GmbH & Co. KG and Contributors
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *    Marc R. Hoffmann - initial API and implementation
12
 * 
13
 *******************************************************************************/
14
15
/**
16
 * CRC64 checksum calculator based on the polynom specified in ISO 3309. The
17
 * implementation is based on the following publications:
18
 * 
19
 * <ul>
20
 * <li>http://en.wikipedia.org/wiki/Cyclic_redundancy_check</li>
21
 * <li>http://www.geocities.com/SiliconValley/Pines/8659/crc.htm</li>
22
 * </ul>
23
 */
24
public class Crc64Helper {
25
    
26
    private static final long POLY64REV = 0xd800000000000000L;
27
    
28
    private static final long[] LOOKUPTABLE;
29
    
30
    private Crc64Helper() {
31
        // Util class
32
    }
33
34
    static {
35
        
36
        LOOKUPTABLE = new long[0x100];
37
        
38
        for (int i = 0; i < 0x100; i++) {
39
            
40
            long v = i;
41
            
42
            for (int j = 0; j < 8; j++) {
43
                if ((v & 1) == 1) {
44
                    v = (v >>> 1) ^ POLY64REV;
45
                } else {
46
                    v = v >>> 1;
47
                }
48
            }
49
            
50
            LOOKUPTABLE[i] = v;
51
        }
52
    }
53
54
    /**
55
     * Calculates the CRC64 checksum for the given data array.
56
     * 
57
     * @param data
58
     *            data to calculate checksum for
59
     * @return checksum value
60
     */
61
    public static String generateCRC64(final byte[] data) {
62
        
63
        long sum = 0;
64
        for (byte element : data) {
65
            
66 2 1. generateCRC64 : Replaced XOR with AND → KILLED
2. generateCRC64 : Replaced bitwise AND with OR → KILLED
            final int lookupidx = ((int) sum ^ element) & 0xff;
67 2 1. generateCRC64 : Replaced Unsigned Shift Right with Shift Left → KILLED
2. generateCRC64 : Replaced XOR with AND → KILLED
            sum = (sum >>> 8) ^ LOOKUPTABLE[lookupidx];
68
        }
69
        
70 1 1. generateCRC64 : replaced return value with "" for com/jsql/util/bruter/Crc64Helper::generateCRC64 → KILLED
        return String.valueOf(sum);
71
    }
72
}

Mutations

66

1.1
Location : generateCRC64
Killed by : StringUtilSpock.[engine:spock]/[spec:StringUtilSpock]/[feature:$spock_feature_0_0]
Replaced XOR with AND → KILLED

2.2
Location : generateCRC64
Killed by : StringUtilSpock.[engine:spock]/[spec:StringUtilSpock]/[feature:$spock_feature_0_0]
Replaced bitwise AND with OR → KILLED

67

1.1
Location : generateCRC64
Killed by : StringUtilSpock.[engine:spock]/[spec:StringUtilSpock]/[feature:$spock_feature_0_0]
Replaced Unsigned Shift Right with Shift Left → KILLED

2.2
Location : generateCRC64
Killed by : StringUtilSpock.[engine:spock]/[spec:StringUtilSpock]/[feature:$spock_feature_0_0]
Replaced XOR with AND → KILLED

70

1.1
Location : generateCRC64
Killed by : StringUtilSpock.[engine:spock]/[spec:StringUtilSpock]/[feature:$spock_feature_0_0]
replaced return value with "" for com/jsql/util/bruter/Crc64Helper::generateCRC64 → KILLED

Active mutators

Tests examined


Report generated by PIT 1.16.1