fletcher

Implementation of the Fletcher checksum algorithm.

Pure Nim score 30/100 · tests present · docs generated

Summary

Latest Version Unknown
License GPLv3+
CI Status Passing
Downloads 0
Last Indexed 2026-07-21 05:24

Installation

nimble install fletcher
choosenim install fletcher
git clone https://github.com/Akito13/nim-fletcher

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
fletcher - - - - - - -

Source

Repository https://github.com/Akito13/nim-fletcher
Homepage https://github.com/Akito13/nim-fletcher
Documentation View Documentation
Registry Source nimble_official

README

nimble

Language

Build Status

GitHub Liberapay patrons

What is this?

This is a Nim module that takes files as arguments and outputs their respective Fletcher checksum. The Fletcher checksum has a bit lower error detection reliability than for example the well known CRC-32 but it is generally a lot faster than for example CRC-32 as well as Adler-32. The project's goal is to provide a very fast checksum algorithm to be used on devices like the Raspberry Pi.

Disclaimer

The project in general is considered Work In Progress. The most reliable variation is Fletcher16, as it is not dependent on the CPU architecture's endianness and the way the algorithm was implemented, is approved to work. The Fletcher32's only weakness is its dependence on the CPU's endianness, which might affect the comparison of checksums between different CPU architectures on different machines, otherwise it is just as stable as Fletcher16.

Currently implemented variations

  • [ ] Fletcher8
  • [x] Fletcher16
  • [ ] Fletcher32
  • [ ] Fletcher64

Tests

nimble test

Runs tests.

The visual test, where you can check the values yourself, is optional:

nimble manualtest

Documentation

nim doc --project fletcher.nim

Creates documentation for the entire project.

Examples

Choose your way of using the API.
from fletcher import fletcher
let
  fileChecksum_1: uint64 = fletcher("myfile.bin", "16")
  fileChecksum_2 = "myfile.bin".fletcher("32b")
  fileChecksum_3: uint64 = fletcher(filename = "myfile.bin", bits = "sixtyfour")
  fileChecksum_4 = "myfile.bin".fletcher # the default is the 16-bit variation
Compare a variable amount of files to a source file by checksum.
from fletcher import fletcherCompare
let
  fileComparison_1: bool = fletcherCompare(bits = "16", original = "path/to/source_file", filenames = "path/to/destfile1", "path/to/destfile2", "path/to/destfile3")
  fileComparison_2 = "16".fletcherCompare("path/to/source_file", "path/to/destfile1", "path/to/destfile2", "path/to/destfile3")

Advanced

For testing purposes and development
nimble configure

Creates a nim.cfg with optimizations as compilation arguments.

nimble clean

Deletes the generated nim.cfg.

TODO

  • make Fletcher32+ independent of CPU architecture
  • add optional Base64 encoding
  • apply delay type optimization
  • apply modulo substitution optimization
  • checksum text
  • ~~varargs file comparison~~
  • ~~import statement optimizations~~
  • ~~add documentation~~

License

Copyright (C) 2020 Akito the@akito.ooo

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.