PHPackages                             dmhendricks/hash-int - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dmhendricks/hash-int

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dmhendricks/hash-int
====================

A PHP class to generate a short hash from an integer.

1.0.0(7y ago)246MITPHPPHP &gt;=4.0.4

Since Oct 9Pushed 6y ago2 watchersCompare

[ Source](https://github.com/dmhendricks/hash-int)[ Packagist](https://packagist.org/packages/dmhendricks/hash-int)[ Docs](https://github.com/dmhendricks/hash-int)[ RSS](/packages/dmhendricks-hash-int/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

[![Release](https://camo.githubusercontent.com/3fba616f1cd3995feec7651c0d8cbf4a6a00a60b6cb53c6ddf1f282d5698fa4c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f646d68656e647269636b732f686173682d696e742e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d363633333939)](https://github.com/dmhendricks/hash-int/releases)[![GitHub License](https://camo.githubusercontent.com/039de44ade043e9e1afb5a4c422c3d89a72146be7104cb24f104adc0cd169fbb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666c61742d737175617265)](https://raw.githubusercontent.com/dmhendricks/hash-int/master/LICENSE)[![Downloads](https://camo.githubusercontent.com/dd5cfd808e747c4610f7abf7e5a1a1cb631557958d75fbbcedfb0b0c0ac50a9d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646d68656e647269636b732f686173682d696e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dmhendricks/hash-int?utm_source=github.com&utm_medium=referral&utm_content=button&utm_campaign=dmhendricks%2Fhash-int)[![DigitalOcean](https://camo.githubusercontent.com/70b3f7391cf23fc69e10caa2a3e68f958a46dfd1eb538ec7016daadd217bab77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f686f7374696e672d4469676974616c2532304f6365616e2d677265656e2e7376673f7374796c653d666c61742d737175617265266c6162656c3d686f7374696e6726636f6c6f72423d303135324646)](https://m.do.co/t/8a88362f5683?utm_source=github.com&utm_medium=campaign&utm_content=referral&utm_campaign=dmhendricks%2Fhash-int)[![Twitter](https://camo.githubusercontent.com/5578c0bcc20fc58bf279d51ad439989834584f009ac1bc3579301099fa342006/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f68747470732f6769746875622e636f6d2f646d68656e647269636b732f686173682d696e742e7376673f7374796c653d736f6369616c)](https://twitter.com/danielhendricks)[![BrowserStack](https://camo.githubusercontent.com/f5f6b1e3ae7ab38a10e6b075cddff32b5c90bcc7f8374a906d4b3b844e6f69c3/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f7374796c653d736f6369616c266c6162656c3d42726f77736572537461636b266d6573736167653d506173736564266c6f676f3d646174613a696d6167652f706e673b6261736536342c6956424f5277304b47676f414141414e5355684555674141414277414141416343414d414141424630792b6d41414141475852465748525462325a30643246795a5142425a4739695a53424a6257466e5a564a6c5957523563636c6c5041414141796870564668305745314d4f6d4e76625335685a4739695a53353462584141414141414144772f654842685932746c644342695a576470626a30693737752f496942705a443069567a564e4d4531775132566f61556836636d5654656b355559337072597a6c6b496a382b494478344f6e68746347316c6447456765473173626e4d366544306959575276596d5536626e4d366257563059533869494867366547317764477339496b466b62324a6c4946684e5543424462334a6c494455754e69316a4d545131494463354c6a45324d7a51354f5377674d6a41784f4338774f4338784d7930784e6a6f304d446f794d6941674943416749434167496a346750484a6b5a6a70535245596765473173626e4d36636d526d50534a6f644852774f693876643364334c6e637a4c6d39795a7938784f546b354c7a41794c7a49794c584a6b5a69317a6557353059586774626e4d6a496a346750484a6b5a6a70455a584e6a636d6c7764476c76626942795a47593659574a76645851394969496765473173626e4d366547317750534a6f644852774f693876626e4d7559575276596d5575593239744c336868634338784c6a41764969423462577875637a70346258424e545430696148523063446f764c32357a4c6d466b62324a6c4c6d4e7662533934595841764d5334774c3231744c79496765473173626e4d36633352535a575939496d6830644841364c793975637935685a4739695a53356a62323076654746774c7a45754d43397a56486c775a5339535a584e7664584a6a5a564a6c5a694d694948687463447044636d566864473979564739766244306951575276596d5567554768766447397a6147397749454e44494449774d546b674b45316859326c756447397a61436b69494868746345314e4f6b6c7563335268626d4e6c53555139496e687463433570615751364e7a51354e6a4579517a4a444d7a55784d5446464f546c424e6b5a444e455647525551335155493452446b69494868746345314e4f6b5276593356745a57353053555139496e68746343356b615751364e7a51354e6a4579517a4e444d7a55784d5446464f546c424e6b5a444e455647525551335155493452446b695069413865473177545530365247567961585a6c5a455a7962323067633352535a5759366157357a644746755932564a52443069654731774c6d6c705a446f334e446b324d544a444d454d7a4e5445784d5555354f554532526b4d3052555a4652446442516a68454f534967633352535a5759365a47396a6457316c626e524a52443069654731774c6d52705a446f334e446b324d544a444d554d7a4e5445784d5555354f554532526b4d3052555a4652446442516a68454f534976506941384c334a6b5a6a70455a584e6a636d6c7764476c76626a3467504339795a475936556b5247506941384c336736654731776257563059543467504439346347466a61325630494756755a4430696369492f5068646656575541414147415545785552586a494d502f5268662f586e346d4868777052586e72593843495846763431536b36384f4143763251432b367376494150356f4541432b364837546f4b61336e503966462f2f41542f2b7466506a567a70545048662b36526631474c636256414a446438502f392b762f7179662f45592f2b6d4e58484c69644b79463132364d762f3236616e6d382f2b3854502f363850316a4146484f386c504159752b534471726837762b78522f30654f67432f724947764d3753764939714b6a41432b366c473577662b534d2f2b326d4f476e4766384e4d674363764c4c4577354f5a4f7630794d6676415252664437762b565366396c5a2f396d4f715473396c7641512f2b454b2f2b56593748722f662b634e302b374c6232464d757146473774754f76396a454f434c4c5039334a4b7a6a2b5a44597777433973324c4c725142386b2f397745762b34522f396f44352f6731623369414143747967434a6f2f2f77364d6e4879504d354d2b68334e75567966634c505a50394d574b4f59584d6576752f2b586e35484730366e574177444738707a6e362f2f6c735a2f6c383572696b2f2b6465662f3338664e6f494c5053332f3174462f2b335a662b73524f6d754943575071336564707272473056545732366a6e2f456874654437434e39696262674338742f39364e506d4c51496a50592f39434b53516649502f2f2f2f2f2f2f2b7441696d4d414141434164464a4f552f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f38414f41564c5a774141416a394a52454655654e705530767462306c4159422f437a435467654472517047777955797a5a77777779426d54524e454c77676b5970515a6b5558756d6b7479724a3133654666397a30435a6438667475665a5a392f7a6e504f63467731484957657a702b7539586d2f39786177386e41534e5873637a664e6b306332564a4f6a476e693266586b5251314b57655764784b42534353533244755a5a736c666c446570505837364c72532f502f2b37333433736c57666b4d524a7175652b646a47586c4963756f33303149482b5552466a552b5a3937617941414549666c384e74784e3347554978574d4e532b615444532f5179734842696a3859584f5443336232314e34446b46497254483935616c742f6a2b6e772b7a306f776d4533324137385564596853324a5a6730616956392f6863317a63314337713468626f6c677830696c67643876754731486f4b35726b7863542f422b6b757348444546476d356f743562366b765a626e4368394e7561372f5235494c5239706944503345567867646f777450507a525235493749497076693762536547535045767a6843426a557033726a516f352f4836504f386d7438436243747875697876506e75743639354a31662b31776e486867414734706d4737764275367036656a3336374f2b63414c5261372f5351517361686a7a4a386b576150726c2b666d793979494556676e55426468513742426a2b382b7545394b4261375761546e7463663245677746486b416c5378744f706b5136314f7078577155417558716f4b6979496777554d56486f46746370634a52636c414a4737417151554e31446c506c74354f4f343441346c6155467669346f596771756a4c423171726a78666e76314a6d527035346776674d476f7747584c38626c446e70596244667050673764704c7936505a6b67566a4372573843673872687067676a715a506a5575476f576d4457513343774f423974522f6379757a6f71433042344f426f56415357666e36554a4d556f3467415642516d5266366265474131787351564a63374556444c3564696e41414f32557563666a6350456b4141414141456c46546b5375516d4343)](https://browserstack.com/?utm_source=github.com&utm_medium=referral&utm_content=link&utm_campaign=dmhendricks%2Fhash-int)

Hash Integer
============

[](#hash-integer)

A PHP class to generate an alphanumeric hash of specified length from an integer.

```
composer require dmhendricks/hash-int

```

### Requirements

[](#requirements)

- PHP 5.6 or higher
- [BC Math](https://www.php.net/manual/en/book.bc.php): `apt install php7.x-bcmath`

### Usage

[](#usage)

```
$num = 456;

/**
 * Create a 7-character hash from integer
 */
$hash = \CloudVerve\HashInt::hash( $num, 7 );

// Unhash the string
$unhashed = \CloudVerve\HashInt::unhash( $hash );

echo 'Hashed: ' . $hash . '';
echo 'Unhashed: ' . $unhashed;
```

### Result

[](#result)

```
Hashed: p3Wq1aC
Unhashed: 456

```

Original [Author](https://github.com/KevBurnsJr) Notes
------------------------------------------------------

[](#original-author-notes)

Paraphrased ([source](http://web.archive.org/web/20130727034425/http://blog.kevburnsjr.com/php-unique-hash)):

> I wanted a short, unique, alphanumeric hash with a sequence that is difficult to deduce. I could create it with md5 and trim the first *n* chars, but storing a truncated checksum in a unique field means that the frequency of collisions will increase geometrically as the number of unique keys for a base 62-encoded integer approaches 62^n. I'd rather do it right than create a time bomb.

### Base 62

[](#base-62)

Hashes are base 62 encoded base 10 integers. 1=1, 10=a, 36=Z, 61=z, 62=10, 72=1a, etc.

### 62, 3844, 238328, 14776336, 916132832, 56800235584, 3521614606208

[](#62-3844-238328-14776336-916132832-56800235584-3521614606208)

1 character = 62 permutations, 2 characters = 3844 permutations, etc.

### 41, 2377, 147299, 9132313, 566201239, 35104476161, 2176477521929

[](#41-2377-147299-9132313-566201239-35104476161-2176477521929)

41 = next highest prime from golden mean of 62.

2377 = next highest prime from golden mean of 3844.

### Uniqueness

[](#uniqueness)

> I chose to use primes to ensure hash uniqueness. Any prime greater than one half 62^n will do, but if you use a prime near 62^n or 62^n/2 or 2\*62^n/3 etc, you will detect a linearity in the sequence at certain points in the ring.

### Appearance of Randomness

[](#appearance-of-randomness)

> I chose primes near the golden ratio to maximize the appearance of randomness. Given a small set of hashes (even with the associated id) it would be difficult for anyone to guess the next hash.

### ⚠️ Minimum-Security Technique

[](#warning-minimum-security-technique)

This is a thin rotation and base re-encoding obfuscation algorithm, not an encryption algorithm. Don't use this to encrypt sensitive information - use it to obfuscate integer IDs or create short reference keys (as an example, for short URLs).

### Special Thanks

[](#special-thanks)

- [Prime Numbers Generator and Checker](https://www.numberempire.com/primenumbers.php?utm_source=github.com&utm_medium=referral&utm_content=link&utm_campaign=dmhendricks%2Fhash-int)
- [Ernesto Preste](https://www.linkedin.com/in/ernesto-preste-4377912b/) for adding [bcmath support](http://web.archive.org/web/20130727034425/http://blog.kevburnsjr.com/php-unique-hash#comment-2792)
- [Padraig Kennedy](https://twitter.com/Padraig) for adding [hash reversibility](http://web.archive.org/web/20130727034425/http://blog.kevburnsjr.com/php-unique-hash#comment-2805)

[![Analytics](https://camo.githubusercontent.com/577336ab601b318ddd3effdf2b65939d3150f7e86b854bd83c5bd1baff759fc2/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d3132363230353736352d312f646d68656e647269636b732f686173682d696e743f666c6174)](https://ga-beacon.appspot.com/?utm_source=github.com&utm_medium=campaign&utm_content=button&utm_campaign=dmhendricks%2Fhash-int)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2774d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c786390f81ee978c57d2648023319ac6dd9c2ddd633574e42c5252a8815e55df?d=identicon)[dmhendricks](/maintainers/dmhendricks)

---

Top Contributors

[![dmhendricks](https://avatars.githubusercontent.com/u/8184361?v=4)](https://github.com/dmhendricks "dmhendricks (8 commits)")[![daniel-thm](https://avatars.githubusercontent.com/u/221158380?v=4)](https://github.com/daniel-thm "daniel-thm (1 commits)")

---

Tags

base62hashhash-functionsshort-idshorturltinyurl-shortener

### Embed Badge

![Health badge](/badges/dmhendricks-hash-int/health.svg)

```
[![Health](https://phpackages.com/badges/dmhendricks-hash-int/health.svg)](https://phpackages.com/packages/dmhendricks-hash-int)
```

###  Alternatives

[phpxmlrpc/polyfill-xmlrpc

A pure-php reimplementation of the API exposed by the native XML-RPC extension

12369.8k2](/packages/phpxmlrpc-polyfill-xmlrpc)[duoshuo/uuid

A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID)

1039.2k](/packages/duoshuo-uuid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
