TL;DR: The algorithm receives a string as input, allocate another string to be the final digest, and start working on them. For each char on the digest (a null character on a first moment), it XORs it with every character from the original string, also XORing it with a set of "random bytes" that are specified in the beginning of the code.
Here are some results:
"000" = qpktluvsqpktluvs; "001" = bcygoiwnccxfohxn;
"abc" = ayedeufryzdfftds; "cba" = cqgleoxlarrnfnvm;
"aaaaa" = hingixcphingixcp; "aabaa" = aprndovlapgneovk;
Am I mathematically getting the full potential of the performance I'm using? How good would you say it is compared to other hashing algorithms? Thanks a lot for reading! This is my first hashing algorithm. My goal is to be simple and performatic. How can I improve it?
#define HASH_LENGTH 16
char *hash(char *input){
// Alphabet and length
const char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
const int alphabetLen = sizeof(alphabet)/sizeof(char) - 1;
// Randomization variables and length
const char vars[] = {
0xA6,
0xC1,
0x5E,
0x31,
0xF5,
0x88,
0xA1,
0xE2
};
const int varsLen = sizeof(vars)/sizeof(char);
// Digest (where the hash is made)
char *digest = (char*)malloc(sizeof(char) * (HASH_LENGTH + 1));
// Input length calculation
int inputLen = 0;
while(input[inputLen] != '\0') inputLen++;
// Digest cleaning
int i;
for(i = 0; i < HASH_LENGTH; i++){
digest[i] = 0;
}
// Hashing process
int j;
for(i = 0; i < HASH_LENGTH; i++){
// XORs digest[i] with vars[input[j]]
for(j = 0; j < HASH_LENGTH; j++){
digest[i] ^= vars[input[j % inputLen] % varsLen];
}
// XORs digest[i] with input[i] + vars[i]
digest[i] ^= input[i % inputLen] + vars[i % varsLen];
}
// Translates digest to desired alphabet
for(i = 0; i < HASH_LENGTH; i++){
j = digest[i] > 0 ? 1 : -1;
digest[i] = alphabet[digest[i] * j % alphabetLen];
}
// Finalizes digest string
*(digest + HASH_LENGTH) = '\0';
return digest;
}
This is how the function is called:
printf("%s", hash("foo"));