I have a function that takes a string as input, and then assigns a product of weighted values to a variable, in the following manner: every letter of the alphabet corresponds to a prime number between 2 and 101, and the value for every character in the input string is multiplied and stored in an int variable, like so:
int result=1;
/* some other code */
result*=letterweight[index];
There are sufficiently long strings that cause an overflow. My question, then, is the following:
How can I determine the possible correct values, given a result?
For instance: if result == 1066849907
, what other value could result have had, neglecting the values range of int
in C?
I do not have control of the original code and cannot determine if an overflow occurred. I am only interested in finding out the series of possible results, however big the numbers might be.