Last active
August 29, 2015 14:11
-
-
Save jwieder/adbd5d1b459eb4df6bfe to your computer and use it in GitHub Desktop.
Very simple implementation of a DGB hash function, written in C. Accepts one contiguous string, provided as a command line argument, as input. For example: #./dgb_hash plaintext
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main(int argc, char* argv[]) | |
{ | |
if (argc != 2) | |
{ | |
printf("\nCorrect usage is: gdb_script plaintext\n"); | |
return 1; | |
} | |
char* plainText = argv[1]; | |
int length = strlen(plainText); | |
int hash = 5381; | |
printf("\nThis is your plaintext: %s\n", plainText); | |
printf("\nThis is your hash value:\n"); | |
for (int i = 0; i < length; i++) | |
{ | |
hash = (((hash << 5) + hash) + plainText[i]) - 'a'; | |
if (i == (length - 1)) printf(" %d\n", hash); | |
else printf(" %d", hash); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment