Hi everyone,

So I am using a C model that I inherited from someone else (no documentation unfortunately). There's a C function (well its developed using the OPNET simulator so it's a sort of a C/OPNET hybrid) that takes a value convert its to a hash value (the dht_get_node_id function) and then that hash can be converted to an int value with the sha_get_int_id function.

Code:
// A bit more semantically-friendly name for a SHA-1 hash.
typedef unsigned char* DhtT_Key_Bytes

DhtT_Key_Bytes 
	dht_get_node_id(int val)

{
      ShaT_Ctx 			context;
      DhtT_Key_Bytes 	key = OPC_NIL;

     FIN (dht_get_node_id(IpT_Address ip_addr_ptr));
			

            sha_init(&context);
 
            // allocate room for the SHA-1 Hash

            key = (DhtT_Key_Bytes) op_prg_mem_alloc(20);
        
            // update() keeps a "running total" of the SHA-1, but since we're only hashing 32 bits, we only use it once

            sha_update(&context, (unsigned char*)&val, sizeof(int));

             // store the final SHA-1 as the DHT ID
            sha_final(key, &context);
 
			printf ("\nThe value of my node ID is: ");
			sha_print_char(key);
Code:
int sha_get_int_id(unsigned char digest[ShaC_Bytes])
{
	int k, runningTotal;
	char	temp;
	
	runningTotal = 0;
	temp = '2';
		
	for (k = 0; k < ShaC_Bytes; k++)
	{
		if (digest[k] == '\a')
		{
			runningTotal += 7;
			//printf("%c", temp);			
		}
		else if(digest[k] != '\a')
		{
			runningTotal += digest[k];
			//printf("%c", digest[k]);	
		}
		
		if (!((k + 1) % 4))
			printf(" ");
	}
	
	return runningTotal;	
}
So for example, from debugging, if I pass the value 5 into the function I get a hash ID of 221 'Y' and if I pass this to sha_get_int_id it gives me an integer ID of 3144.

My problem is that I need a way of converting an integer back into the appropriate hash ID e.g. converting 3144 back to 221 'Y'.

Can anyone give me any advice as to how I can go about this? I suppose what's confusing me is the whole hash/digest thing which I'm not sure I fully follow and whether it's even possible to convert back (because from my limited knowledge maybe that's the whole point that you can't convert back because this is used for encryption).

Many thanks in advance.