Git Product home page Git Product logo

php-fnv1a's Introduction

PHP implementation of Fowler–Noll–Vo 1a

Copyright 2017-2021 Philippe Paquet


Description

Fowler–Noll–Vo 1a is a variant of the non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Kiem-Phong Vo.

For the specifications, check the IETF draft.

For some history, check Landon Curt Noll website

This implementation of FNV 1a includes all the specified bit sizes (32, 64, 128, 256, 512 and 1024 bits) and includes a set of test vectors.


Usage

Include the header corresponding to the bit size required:

require_once('include/fnv1a_32.inc.php');		// 32 bits
require_once('include/fnv1a_64.inc.php');		// 64 bits
require_once('include/fnv1a_128.inc.php');		// 128 bits
require_once('include/fnv1a_256.inc.php');		// 256 bits
require_once('include/fnv1a_512.inc.php');		// 512 bits
require_once('include/fnv1a_1024.inc.php');		// 1024 bits

Call the function corresponding to the bit size required:

function fnv1a_32_str($string);		// 32 bits
function fnv1a_64_str($string);		// 64 bits
function fnv1a_128_str($string);	// 128 bits
function fnv1a_256_str($string);	// 256 bits
function fnv1a_512_str($string);	// 512 bits
function fnv1a_1024_str($string);	// 1024 bits

The functions take a string as input parameter and returns an hexadecimal string.


Example

<?php

require_once('include/fnv1a_32.inc.php');
require_once('include/fnv1a_64.inc.php');
require_once('include/fnv1a_128.inc.php');

$string = 'foobar';

echo 'String: ' . $string . PHP_EOL;
echo PHP_EOL;
echo 'FNV1a 32 bits: ' . fnv1a_32_str($string) . PHP_EOL;
echo 'FNV1a 64 bits: ' . fnv1a_64_str($string) . PHP_EOL;
echo 'FNV1a 128 bits: ' . fnv1a_128_str($string) . PHP_EOL;

Will display the following:

String: foobar

FNV1a 32 bits: bf9cf968
FNV1a 64 bits: 85944171f73967e8
FNV1a 128 bits: 343e1662793c64bf6f0d3597ba446f18

Test vectors

You can use test_vectors.php to test the implementation:

php test_vectors.php

Should return the following:

fnv1a_32_str successfully tested
fnv1a_64_str successfully tested
fnv1a_128_str successfully tested
fnv1a_256_str successfully tested
fnv1a_512_str successfully tested
fnv1a_1024_str successfully tested

Contributing

Bug reports and suggestions for improvements are most welcome.


Contact

If you have any questions, comments or suggestions, do not hesitate to contact me at [email protected]

php-fnv1a's People

Contributors

philippelyp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

php-fnv1a's Issues

FNV1a 52 bit

Hello, great lib thank you.

I was wondering if you could please add 52bit function(s) too.

I am happened to be in a situation where I need to move functionality from javascript to php.
I have FNV1a 52bit used in javascript from this class: https://github.com/tjwebb/fnv-plus/blob/master/index.js
In this class 52bit and 64bit functions are very similar, so maybe it is easy to do for php too (as we have the 64bit one in this repo)

I'm trying to do this myself, if I get it to work I share it here. But I am not that confident I can do this. Could you please have a look?

Thank you

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.