Added 'CRC-16 Checksum' operation

feature-extract-files
n1474335 2017-09-12 15:50:46 +00:00
parent 3c52a9faab
commit 174cabdc74
6 changed files with 30 additions and 31 deletions

5
package-lock.json generated
View File

@ -4198,6 +4198,11 @@
"integrity": "sha1-8OgK4DmkvWVLXygfyT8EqRSn/M4=", "integrity": "sha1-8OgK4DmkvWVLXygfyT8EqRSn/M4=",
"dev": true "dev": true
}, },
"js-crc": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/js-crc/-/js-crc-0.2.0.tgz",
"integrity": "sha1-9yxcdhgXa/91zIEqHO2949jraDk="
},
"js-sha3": { "js-sha3": {
"version": "0.6.1", "version": "0.6.1",
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.6.1.tgz", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.6.1.tgz",

View File

@ -76,6 +76,7 @@
"exif-parser": "^0.1.12", "exif-parser": "^0.1.12",
"google-code-prettify": "^1.0.5", "google-code-prettify": "^1.0.5",
"jquery": "^3.1.1", "jquery": "^3.1.1",
"js-crc": "^0.2.0",
"js-sha3": "^0.6.1", "js-sha3": "^0.6.1",
"jsbn": "^1.1.0", "jsbn": "^1.1.0",
"jsonpath": "^0.2.12", "jsonpath": "^0.2.12",

View File

@ -261,6 +261,7 @@ const Categories = [
"Fletcher-32 Checksum", "Fletcher-32 Checksum",
"Fletcher-64 Checksum", "Fletcher-64 Checksum",
"Adler-32 Checksum", "Adler-32 Checksum",
"CRC-16 Checksum",
"CRC-32 Checksum", "CRC-32 Checksum",
"TCP/IP Checksum", "TCP/IP Checksum",
] ]

View File

@ -3040,7 +3040,14 @@ const OperationConfig = {
"CRC-32 Checksum": { "CRC-32 Checksum": {
description: "A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.<br><br>The CRC was invented by W. Wesley Peterson in 1961; the 32-bit CRC function of Ethernet and many other standards is the work of several researchers and was published in 1975.", description: "A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.<br><br>The CRC was invented by W. Wesley Peterson in 1961; the 32-bit CRC function of Ethernet and many other standards is the work of several researchers and was published in 1975.",
run: Checksum.runCRC32, run: Checksum.runCRC32,
inputType: "byteArray", inputType: "string",
outputType: "string",
args: []
},
"CRC-16 Checksum": {
description: "A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.<br><br>The CRC was invented by W. Wesley Peterson in 1961.",
run: Checksum.runCRC16,
inputType: "string",
outputType: "string", outputType: "string",
args: [] args: []
}, },

View File

@ -1,3 +1,4 @@
import * as CRC from "js-crc";
import Utils from "../Utils.js"; import Utils from "../Utils.js";
@ -119,19 +120,24 @@ const Checksum = {
/** /**
* CRC-32 Checksum operation. * CRC-32 Checksum operation.
* *
* @param {byteArray} input * @param {string} input
* @param {Object[]} args * @param {Object[]} args
* @returns {string} * @returns {string}
*/ */
runCRC32: function(input, args) { runCRC32: function(input, args) {
let crcTable = global.crcTable || (global.crcTable = Checksum._genCRCTable()), return CRC.crc32(input);
crc = 0 ^ (-1); },
for (let i = 0; i < input.length; i++) {
crc = (crc >>> 8) ^ crcTable[(crc ^ input[i]) & 0xff];
}
return Utils.hex((crc ^ (-1)) >>> 0); /**
* CRC-16 Checksum operation.
*
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
runCRC16: function(input, args) {
return CRC.crc16(input);
}, },
@ -168,28 +174,6 @@ const Checksum = {
return Utils.hex(0xffff - csum); return Utils.hex(0xffff - csum);
}, },
/**
* Generates a CRC table for use with CRC checksums.
*
* @private
* @returns {array}
*/
_genCRCTable: function() {
let c,
crcTable = [];
for (let n = 0; n < 256; n++) {
c = n;
for (let k = 0; k < 8; k++) {
c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
}
crcTable[n] = c;
}
return crcTable;
},
}; };
export default Checksum; export default Checksum;

View File

@ -346,7 +346,8 @@ const Hash = {
"\nFletcher-32: " + Checksum.runFletcher32(byteArray, []) + "\nFletcher-32: " + Checksum.runFletcher32(byteArray, []) +
"\nFletcher-64: " + Checksum.runFletcher64(byteArray, []) + "\nFletcher-64: " + Checksum.runFletcher64(byteArray, []) +
"\nAdler-32: " + Checksum.runAdler32(byteArray, []) + "\nAdler-32: " + Checksum.runAdler32(byteArray, []) +
"\nCRC-32: " + Checksum.runCRC32(byteArray, []); "\nCRC-16: " + Checksum.runCRC16(input, []) +
"\nCRC-32: " + Checksum.runCRC32(input, []);
return output; return output;
}, },