An open API service indexing awesome lists of open source software.

https://github.com/moccalotto/idhash

Create Reversible Hashes from integers.
https://github.com/moccalotto/idhash

hashes integer-compression obfuscation php

Last synced: about 1 month ago
JSON representation

Create Reversible Hashes from integers.

Awesome Lists containing this project

README

          

# IdHash
[![Build Status](https://travis-ci.org/moccalotto/idhash.svg)](https://travis-ci.org/moccalotto/idhash)

A reversible (integer) ID obfuscator

Create hashes like the ones used by imgur, pastebin, youtube, etc.

Default keyspace is the standard base62 keyspace.

## Installation

To add this package as a local, per-project dependency to your project, simply add a dependency on
`moccalotto/idhash` to your project's `composer.json` file like so:

```json
{
"require": {
"moccalotto/idhash": "~0.9"
}
}
```

Alternatively simply call `composer require moccalotto/idhash`

```php
key();

// initialize a new IntHasher
$IntHasher = new IntHasher($key);

// generate new input value
$input_int = mt_rand();

// encode the integer into a hash
$hash_str = $IntHasher->intToHash($input_int);

// decode the hash into an integer
$output_int = $IntHasher->hashToInt($hash_str);

// print the process values to screen
printf('The generated key: %s%s', $key->keyString(), PHP_EOL);
printf('Number to encode: %d%s', $input_int, PHP_EOL);
printf('The encoded hash: %s%s', $hash_str, PHP_EOL);
printf('Decoded number: %s%s', $output_int, PHP_EOL);
printf('Success: %s%s', $input_int === $output_int ? 'Yes' : 'NO!', PHP_EOL);

die($input_int !== $output_int);
```