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.
// A bit more semantically-friendly name for a SHA-1 hash.
typedef unsigned char* DhtT_Key_Bytes
DhtT_Key_Bytes key = OPC_NIL;
FIN (dht_get_node_id(IpT_Address ip_addr_ptr));
// 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
printf ("\nThe value of my node ID is: ");
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.
int sha_get_int_id(unsigned char digest[ShaC_Bytes])
int k, runningTotal;
runningTotal = 0;
temp = '2';
for (k = 0; k < ShaC_Bytes; k++)
if (digest[k] == '\a')
runningTotal += 7;
else if(digest[k] != '\a')
runningTotal += digest[k];
if (!((k + 1) % 4))
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.