/bitrot-fixer

Fixes files corrupted by bit-rot by flipping bits until the stored checksum matches

Primary LanguageJava

Bitrot Fixer

If you have a file (jpeg, mp3, etc) which has become corrupted by bit rot, and you know what the correct hash should be, this CLI project will try and flip every bit in the file until it finds the one that is incorrect.
The fixed file is saved as -fixed

Runs the hash operations across all available cores for speed improvements

Args:

Mandatory: file to check
Mandatory: correct hash
Optional: 1 or 2 flipped bits to try

Usage

./mvnw clean package
java -jar target/bitrot-fixer-1.0-SNAPSHOT.jar src/test/resources/test-image-two-flips.jpeg md5:8a673261e62cdfc9072b0dc3ee4d21eb 2

Native

To build a native Linux image, download the Graal JDK

JAVA_HOME=/path/to/graaljdk ./mvnw -DskipTests -Pnative clean package
target/bitrot-fixer src/test/resources/test-image-two-flips.jpeg md5:8a673261e62cdfc9072b0dc3ee4d21eb 2

Currently supported hash algorithms:

  • crc32
  • crc32c
  • md5
  • sha1
  • sha256
  • sha384
  • sha512
  • sha3_256

Current limitations

  • Trying two bit-flips takes a very long time on large files, due to all the possible combinations (<filesize>²)