For example:
#./gdb_script < input_file.txt
or
#./gdb_script thisismystring
Each character in the string is input as a non-contiguous block of integers, for simplicity in reviewing output.
Enjoy!
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; | |
} |
No comments:
Post a Comment