GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Mar-2004, 23:41
jack jack is offline
New Member
 
Join Date: Jan 2004
Posts: 15
jack is on a distinguished road

urgent help:hash function


Hi can anyone provide me with a simple hash function that takes values for e.g numbers and alphabets. let say
int i =23544564;
char a= jack;
int j=123;
int x= 202.020.22.0

and convert it to return a hash string like as4546wui

thanx
jack
  #2  
Old 15-Mar-2004, 23:49
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Looks like you're in the wrong place. This is a forum designed to help people solve problems. If you're looking for source code, you might want to check out this website:

http://www.sourceforge.net
__________________
-Aaron
  #3  
Old 03-Apr-2004, 21:20
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Jack, you can't receive PM's because your mail account is filled up, so I posted a reply to you here, since it is a similar question and hopefully you will get an email message about a post.

Quote:
Originally Posted by jack
hi can you provide me a simple example to do a hash with md5 in C
thanx.
jack

Hi Jack.

I don't know much of anything about md5. I put together this simple sample, but I have no idea if it works right or not. If you know what you are trying to do this might get you started. Please note that you will need the openssl libraries.

CPP / C++ / C Code:
include <openssl/md5.h>
#include <stdio.h>

int main()
{
	char 	string[100];
	char*	hash = 0;
	
	printf("Enter string to hash: ");
	fgets(string,100,stdin);
	hash = MD5(string,strlen(string),hash);
	
	printf("The hash is: %s\n",hash);

	return 0;
}

When you compile you need to link with the ssl library. In gcc I did:
Code:
gcc md5.c -lssl -o md5

Hope this gets you started.
  #4  
Old 04-Apr-2004, 09:29
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Try this instead. The hash seems to work okay, it was the way that I was printing it that gave the difference. I get the exact same thing using md5sum as I do using this.

CPP / C++ / C Code:
#include <openssl/md5.h>
#include <stdio.h>

int main()
{
	char 	string[100];
	unsigned char*	hash = 0;
	unsigned char*	parse;
	
	printf("Enter string to hash: ");
	fgets(string,100,stdin);
	hash = MD5(string,strlen(string),hash);
	
	printf("The hex hash value is: ");
	parse = hash;
	while(*parse){
		printf("%02x",*parse);
		parse++;
	}
	printf("\n");
	
	return 0;
}
  #5  
Old 05-Apr-2004, 08:47
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Dave. If you are using *nix, you should try pulling up the man page for md5. It should tell you everything about the function that you want to know. Here is the basic format of MD5:

Quote:
unsigned char *MD5(const unsigned char *d, unsigned long n,unsigned char *md)

So while
CPP / C++ / C Code:
 
hash = MD5(string,strlen(string),hash);
will hash the entire string, using
CPP / C++ / C Code:
hash = MD5(string,8,hash);
will hash only the first 8 characters of the string.

Also, could you please respond back in this thread? It is kind of a pain to do this through PM's and it makes me look like I am adding comments to this thread for the fun of it.

cheers,
d
  #6  
Old 05-Apr-2004, 13:18
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
I think I might have scared him away ??:
__________________
-Aaron
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent ! Pls Help Me ! mycashmoney C Programming Language 4 01-Jul-2006 23:49
Calling functions within a function spudtheimpaler C Programming Language 5 02-Mar-2004 09:02
urgent needs :apache + random function jack Apache Web Server Forum 0 19-Jan-2004 18:41
i/o: set value x (long) before it is used by a function gmn C Programming Language 1 18-Nov-2003 02:12
[class] 404 search function code jrobbio MySQL / PHP Forum 6 22-Apr-2003 10:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:27.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.