Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,379 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,031 people online right now. Registration is fast and FREE... Join Now!




What hashing algorithm outputs numbers only?

2 Pages V  1 2 >  
Reply to this topicStart new topic

What hashing algorithm outputs numbers only?

wkatz
10 Sep, 2006 - 07:28 AM
Post #1

New D.I.C Head
*

Joined: 10 Sep, 2006
Posts: 2


My Contributions
Hi, Gurus. What hashing algorithm outputs hash value as numbers only? For example, if you pass a “John Q. Public” it will output 23324. If there is no such hashing, how hard is it to hire somebody to write a fairly quick one? It could be some fast hashing and then another function that creates numbers. Much obliged. wkatz.
User is offlineProfile CardPM
+Quote Post

Xing
RE: What Hashing Algorithm Outputs Numbers Only?
10 Sep, 2006 - 08:27 AM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
You can use map for this
http://www.sgi.com/tech/stl/Map.html
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: What Hashing Algorithm Outputs Numbers Only?
12 Sep, 2006 - 08:00 AM
Post #3

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
I'm not sure if I perfectly understood your question/project but it seems you want to input a string and output it as a number.

Please clarify and we'll help you out.
Does it need encryption or simply coverting letters or numbers?
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: What Hashing Algorithm Outputs Numbers Only?
12 Sep, 2006 - 10:45 AM
Post #4

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,935



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
You can write your own hashing function too.
But that depends on the level of security that you need for your application.

If the security needed isn't much, then you can get the ASCII Values of all the characters, perform various mathematical functions on them and return the result as the Hash Value.

How important is the security of the Hash Algorithm in your Application?
Answering that will help us give you better solutions.
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: What Hashing Algorithm Outputs Numbers Only?
12 Sep, 2006 - 12:05 PM
Post #5

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
True, simply replacing the letters in their ASCII value is the best solution

CODE
for(a = 0, a != str.length(), ++a)
cout<<int(str[a])<<", ";


Although the conversion to string -> int might not work, there are ways to work around it.

This post has been edited by DeeViLiSh: 12 Sep, 2006 - 12:05 PM
User is offlineProfile CardPM
+Quote Post

BlueVD
RE: What Hashing Algorithm Outputs Numbers Only?
12 Sep, 2006 - 02:22 PM
Post #6

New D.I.C Head
Group Icon

Joined: 8 Aug, 2005
Posts: 29



Thanked: 1 times
Dream Kudos: 75
My Contributions
You'll notice from the image... Most well known hashing algorithms use alphanumeric characters. You can't get the strengh and flexibility of a hash using only one type of glyphs. There are a lot of classes, etc out there that cand do it for you. If you were to post a much more detailed example as to why you want only numbers, maybe a better solution could be found.


Attached thumbnail(s)
Attached Image
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: What Hashing Algorithm Outputs Numbers Only?
12 Sep, 2006 - 04:33 PM
Post #7

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
QUOTE(DeeViLiSh @ 12 Sep, 2006 - 12:00 PM) *

I'm not sure if I perfectly understood your question/project but it seems you want to input a string and output it as a number.

Please clarify and we'll help you out.
Does it need encryption or simply coverting letters or numbers?

You may wish to research hashing vs. encryption...there is a difference. the user is asking about hash algorithms, not encryption methodology.
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: What Hashing Algorithm Outputs Numbers Only?
12 Sep, 2006 - 09:54 PM
Post #8

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
o.O They are diff. and there are way more hashing algos then encryption methods...

New topic for me, thx Amadeus.
User is offlineProfile CardPM
+Quote Post

wkatz
RE: What Hashing Algorithm Outputs Numbers Only?
15 Sep, 2006 - 06:03 AM
Post #9

New D.I.C Head
*

Joined: 10 Sep, 2006
Posts: 2


My Contributions
QUOTE(Amadeus @ 12 Sep, 2006 - 05:33 PM) *

QUOTE(DeeViLiSh @ 12 Sep, 2006 - 12:00 PM) *

I'm not sure if I perfectly understood your question/project but it seems you want to input a string and output it as a number.

Please clarify and we'll help you out.
Does it need encryption or simply coverting letters or numbers?

You may wish to research hashing vs. encryption...there is a difference. the user is asking about hash algorithms, not encryption methodology.

DeeViLiSh, everybody else - thanks for the post. There is no encryption. I just need a function that will hash character to numbers and back. This process has to be 100% consistent (always return the same number) and reversible. For example, if this function hashes "John Q. Public" into 343444, the only value returned back from this 343444 will be "John Q. Public". wink2.gif That is all. Please let me know if you can help.
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: What Hashing Algorithm Outputs Numbers Only?
15 Sep, 2006 - 12:57 PM
Post #10

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
All you really need to do is convert a letter into a number?
Well use born2c0de's suggestion, using
a string,
str.length(); ,
a for loop,
and int(str[a]),

you basically have your program wirtten out.

Note : Please post some code next time to show some efforts

PS : Checking out some of my snippets might answer or contribute to your question.

This post has been edited by DeeViLiSh: 15 Sep, 2006 - 12:58 PM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: What Hashing Algorithm Outputs Numbers Only?
15 Sep, 2006 - 05:13 PM
Post #11

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Hashing is not simple substitution...here is an article you may find enlightening.

http://en.wikipedia.org/wiki/Hash_function
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: What Hashing Algorithm Outputs Numbers Only?
16 Sep, 2006 - 12:29 AM
Post #12

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
To whom was that comment pointed at?
From his post, it seems he is talking about a simple substitution, I agree that the way I posted it doesn't explain hashing but indeed a simple substitution.
If the main idea is to convert letters into numbers without using an algorithm...
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 12/5/08 01:43AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month