Giter VIP home page Giter VIP logo

rabinfingerprint's Introduction

rabinfingerprint

A Java implementation of the rabin fingerprinting method. (http://en.wikipedia.org/wiki/Rabin_fingerprint)

Optimized for use on a stream including a sliding window fingerprint.

Includes arbitrary-precision-polynomial hashing as well as very fast long-based hashing implementations, which are best for most hashing uses.

Generating a fingerprint

// Create new random irreducible polynomial
// These can also be created from Longs or hex Strings
Polynomial polynomial = Polynomial.createIrreducible(53);

// Create a fingerprint object
RabinFingerprintLong rabin = new RabinFingerprintLong(polynomial);

// Push bytes from a file stream
rabin.pushBytes(ByteStreams.toByteArray(new FileInputStream("file.test")));

// Get fingerprint value and output
System.out.println(Long.toString(rabin.getFingerprintLong(), 16));

Generating a sliding-window fingerprint

// Create new random irreducible polynomial
// These can also be created from Longs or hex Strings
Polynomial polynomial = Polynomial.createIrreducible(53);

// Create a windowed fingerprint object with a window size of 48 bytes.
RabinFingerprintLongWindowed window = new RabinFingerprintLongWindowed(polynomial, 48);
for (byte b : ByteStreams.toByteArray(new FileInputStream("file.test"))) {
	// Push in one byte. Old bytes are automatically popped.
	window.pushByte(b);
	// Output current window's fingerprint
	System.out.println(Long.toString(window.getFingerprintLong(), 16));
}

Building

This project uses Maven for dependency management. To build this project's runnable jar, sources and javadoc, run this command:

% mvn clean install

Command line

Full Usage

Generate a new irreducible polynomial

% java -jar rabinfingerprint.jar -polygen 53
3DE9DD57CA448B

Fingerprint a file

% java -jar rabinfingerprint.jar -p 3DE9DD57CA448B file.test
43A39C59491F /[path to file]/file.test

Fingerprint STDIN

% cat file.test | java -jar rabinfingerprint.jar -p 3DE9DD57CA448B
43A39C59491F

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.