Added Fletcher-8, -32 and -64 checksum operations. Closes #51.

This commit is contained in:
n1474335 2017-01-17 15:52:24 +00:00
parent cddd349090
commit 3c3f5d9dcd
9 changed files with 120 additions and 45 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -226,7 +226,10 @@ var Categories = [
"SHA3",
"RIPEMD-160",
"HMAC",
"Fletcher-8 Checksum",
"Fletcher-16 Checksum",
"Fletcher-32 Checksum",
"Fletcher-64 Checksum",
"Adler-32 Checksum",
"CRC-32 Checksum",
"TCP/IP Checksum",

View File

@ -2642,6 +2642,13 @@ var OperationConfig = {
},
]
},
"Fletcher-8 Checksum": {
description: "The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John Gould Fletcher at Lawrence Livermore Labs in the late 1970s.<br><br>The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques.",
run: Checksum.run_fletcher8,
input_type: "byte_array",
output_type: "string",
args: []
},
"Fletcher-16 Checksum": {
description: "The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John Gould Fletcher at Lawrence Livermore Labs in the late 1970s.<br><br>The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques.",
run: Checksum.run_fletcher16,
@ -2649,6 +2656,20 @@ var OperationConfig = {
output_type: "string",
args: []
},
"Fletcher-32 Checksum": {
description: "The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John Gould Fletcher at Lawrence Livermore Labs in the late 1970s.<br><br>The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques.",
run: Checksum.run_fletcher32,
input_type: "byte_array",
output_type: "string",
args: []
},
"Fletcher-64 Checksum": {
description: "The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John Gould Fletcher at Lawrence Livermore Labs in the late 1970s.<br><br>The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques.",
run: Checksum.run_fletcher64,
input_type: "byte_array",
output_type: "string",
args: []
},
"Adler-32 Checksum": {
description: "Adler-32 is a checksum algorithm which was invented by Mark Adler in 1995, and is a modification of the Fletcher checksum. Compared to a cyclic redundancy check of the same length, it trades reliability for speed (preferring the latter).<br><br>Adler-32 is more reliable than Fletcher-16, and slightly less reliable than Fletcher-32.",
run: Checksum.run_adler32,

View File

@ -9,6 +9,26 @@
*/
var Checksum = {
/**
* Fletcher-8 Checksum operation.
*
* @param {byte_array} input
* @param {Object[]} args
* @returns {string}
*/
run_fletcher8: function(input, args) {
var a = 0,
b = 0;
for (var i = 0; i < input.length; i++) {
a = (a + input[i]) % 0xf;
b = (b + a) % 0xf;
}
return Utils.hex(((b << 4) | a) >>> 0, 2);
},
/**
* Fletcher-16 Checksum operation.
*
@ -27,6 +47,46 @@ var Checksum = {
return Utils.hex(((b << 8) | a) >>> 0, 4);
},
/**
* Fletcher-32 Checksum operation.
*
* @param {byte_array} input
* @param {Object[]} args
* @returns {string}
*/
run_fletcher32: function(input, args) {
var a = 0,
b = 0;
for (var i = 0; i < input.length; i++) {
a = (a + input[i]) % 0xffff;
b = (b + a) % 0xffff;
}
return Utils.hex(((b << 16) | a) >>> 0, 8);
},
/**
* Fletcher-64 Checksum operation.
*
* @param {byte_array} input
* @param {Object[]} args
* @returns {string}
*/
run_fletcher64: function(input, args) {
var a = 0,
b = 0;
for (var i = 0; i < input.length; i++) {
a = (a + input[i]) % 0xffffffff;
b = (b + a) % 0xffffffff;
}
return Utils.hex(b >>> 0, 8) + Utils.hex(a >>> 0, 8);
},
/**

View File

@ -215,7 +215,10 @@ var Hash = {
"\nSHA3 512: " + Hash.run_sha3(input, ["512"]) +
"\nRIPEMD-160: " + Hash.run_ripemd160(input, []) +
"\n\nChecksums:" +
"\nFletcher-8: " + Checksum.run_fletcher8(byte_array, []) +
"\nFletcher-16: " + Checksum.run_fletcher16(byte_array, []) +
"\nFletcher-32: " + Checksum.run_fletcher32(byte_array, []) +
"\nFletcher-64: " + Checksum.run_fletcher64(byte_array, []) +
"\nAdler-32: " + Checksum.run_adler32(byte_array, []) +
"\nCRC-32: " + Checksum.run_crc32(byte_array, []);

View File

@ -1,9 +1,9 @@
211 source files
114750 lines
210 source files
114779 lines
4.3M size
141 JavaScript source files
105592 lines
105679 lines
3.7M size
83 third party JavaScript source files
@ -11,11 +11,11 @@
3.0M size
58 first party JavaScript source files
19334 lines
728K size
19421 lines
732K size
3.4M uncompressed JavaScript size
1.8M compressed JavaScript size
1.9M compressed JavaScript size
15 categories
162 operations
165 operations