# Hash/encode a numeric id like 12567889 to aphabatic characters like 'aty'

hi
i am creating a application were i have to create a hashed/encoded code for each id in databse table. id's length is about 7 digits like 16,66,189. No i want to convert this into small encoded value like 'aty' lenght of about 3-4 digits. Which is mathematically equilant to its's numeric value. So that i can convert for numeric value to encoded value and vice versa.

Any sugestion how this can be achived. I tried many ways but all of them gives a long hashed/encoded value which defeats the purpose of creating small encoded value.

Thanks
C#Regular ExpressionsAlgorithms

Last Comment
knowledge_riot
Jaime Olivares

sound like you need a base64 encoding or similar
I think this encoder will suit better your needs:
http://www.codeproject.com/KB/recipes/ExpandableHexConverter.aspx
With your 7 digit number there are 9,999,999 possible permutations
Even a 4 letter string with mixed case is not long enough to give the required number of permutations, see calculations below. You'd need at least a 5 letter string.
3 letter string, all lowercase = 26 ^ 3 = 17,576 permutations
3 letter string, mixed case = 52 ^ 3 = 140,608 permutations
4 letter string, all lowercase = 26 ^ 4 = 456,976 permutations
4 letter string, mixed case = 52 ^ 4 = 7,311,616 permutations
5 letter string, all lowercase = 26 ^ 5 = 11,881,376 permutations
What is the reasoning for needing to store an alphabetic ID? Storing an integer is much more efficient than storing a 5 letter string.
ozo

4 character string, letters and digits = 62^4 = 14776336
SaiRajeshShashi

thanks i guess 5 letter string is alright but how can i convert number to letters.
Jaime Olivares

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts

TRUSTED BY