Compute Fletcher Checksums (16, 32, and 64 Bit)

Computes Fletcher's position-dependent checksum in 16-, 32-, and 64-bit widths. Fletcher's checksum, devised by John G. Fletcher, provides error-detection properties approaching a cyclic redundancy check at lower computational cost. Input is processed as little-endian words with the final partial word zero-padded, so results are reproducible across platforms.


fletcher

Fletcher's checksum for R, in 16-, 32-, and 64-bit widths.

Fletcher's checksum keeps two running sums as it walks the input and concatenates them into the result. It catches the reordering and single-bit errors a plain sum misses, at a fraction of the cost of a CRC. The algorithm lives in C; the R side is a thin wrapper.

Install

# install.packages("remotes")
remotes::install_github("chrislongros/fletcher")

Use

library(fletcher)

fletcher("abcde", 16)  # "c8f0"
fletcher("abcde", 32)  # "f04fc729"
fletcher("abcde", 64)  # "c8c6c527646362c6"

x can be a string, a raw vector, or a vector of byte values:

fletcher(charToRaw("abcde"), 32)          # "f04fc729"
fletcher(as.integer(charToRaw("abcde")))  # width defaults to 32

The result is a lowercase hex string of width / 4 characters.

Details

Input is read as little-endian words, so the output does not depend on the host's byte order. A final partial word is zero-padded. The running sums start at zero and reduce modulo 2^(width/2) - 1; the checksum is the high sum shifted over the low sum.

License

MIT.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("fletcher")

0.1.0 by Christos Longros, 3 months ago


https://github.com/chrislongros/fletcher


Report a bug at https://github.com/chrislongros/fletcher/issues


Browse source code at https://github.com/cran/fletcher


Authors: Christos Longros [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Suggests tinytest


See at CRAN