2018-05-17 17:11:34 +02:00
/ * *
* @ author n1474335 [ n1474335 @ gmail . com ]
* @ copyright Crown Copyright 2016
* @ license Apache - 2.0
* /
2019-07-09 13:23:59 +02:00
import Operation from "../Operation.mjs" ;
import Utils from "../Utils.mjs" ;
2018-05-17 17:11:34 +02:00
/ * *
* Adler - 32 Checksum operation
* /
class Adler32Checksum extends Operation {
/ * *
* Adler32Checksum constructor
* /
constructor ( ) {
super ( ) ;
this . name = "Adler-32 Checksum" ;
2018-12-26 00:58:00 +01:00
this . module = "Crypto" ;
2018-05-17 17:11:34 +02:00
this . 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." ;
2018-08-21 20:07:13 +02:00
this . infoURL = "https://wikipedia.org/wiki/Adler-32" ;
2019-07-29 18:09:46 +02:00
this . inputType = "ArrayBuffer" ;
2018-05-17 17:11:34 +02:00
this . outputType = "string" ;
this . args = [ ] ;
}
/ * *
2019-07-29 18:09:46 +02:00
* @ param { ArrayBuffer } input
2018-05-17 17:11:34 +02:00
* @ param { Object [ ] } args
* @ returns { string }
* /
run ( input , args ) {
const MOD _ADLER = 65521 ;
let a = 1 ,
b = 0 ;
2019-07-29 18:09:46 +02:00
input = new Uint8Array ( input ) ;
2018-05-17 17:11:34 +02:00
for ( let i = 0 ; i < input . length ; i ++ ) {
a += input [ i ] ;
b += a ;
}
a %= MOD _ADLER ;
b %= MOD _ADLER ;
return Utils . hex ( ( ( b << 16 ) | a ) >>> 0 , 8 ) ;
}
}
export default Adler32Checksum ;