I'm creating a hashing program that takes either a file or stdin and prints out the hash in either another file or to the terminal via stdout. My issue is I'm getting different hash values based on the same stdin because the hex values of the argument change.
the part of my code where this happens is here:
for (i = 3; i < argc; i++) {
if (strcmp(argv[i], "-i") == 0 && argv[i+1] != NULL) {
in = argv[i+1];
in = strtok(in, " ");
printf("arg \"%s\" hex: %02x\n", argv[i+1], argv[i+1]);
inCheck = 1;
i++;
}
else if (strcmp(argv[i], "-o") == 0 && argv[i+1] != NULL) {
out = argv[i+1];
i++;
}
else
printf("Unknown argument %s. Ignoring.\n", argv[i]);
}
Basically here I'm checking the hex-value of the input following "-i" in the command line. And when I enter:
./executable hash -sha -i hello -o world
I get the output arg "hello" hex: ce4a2823
and when I enter:
./executable hash -sha -i hello
I get the output arg "hello" hex: 247f582c
and when I enter:
./executable hash -sha -o world -i hello
I get the output arg "hello" hex: 57e2f82c
So I'm wondering why the hex-value of the string keeps changing?