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.
- Host: GitHub
- URL: https://github.com/moccalotto/idhash
- Owner: moccalotto
- License: mit
- Created: 2015-11-30T11:29:02.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-07-29T17:04:59.000Z (over 7 years ago)
- Last Synced: 2025-07-08T05:57:05.389Z (8 months ago)
- Topics: hashes, integer-compression, obfuscation, php
- Language: PHP
- Homepage: https://moccalotto.github.io/docs/idhash
- Size: 25.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# IdHash
[](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);
```