So, I have this:
I know that some code was used to generate a random sequence, and it looked roughly like this:
#include <iostream>
#include <string>
int main() {
const std::string alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
std::string temp = "1234567890";
srand(MAGICNUMBER);
for (int i = 0;; ++i) {
for (int j = 0; j < 10; ++j) {
temp[j] = alphabet[rand() % alphabet.size()];
}
std::cout << temp << std::endl;
}
}
It was used to generate a sequence of 124660967 strings, the last of which was "2lwd9JjVnE", and then stopped. The compilator used was 64-bit g++ 4.8 for Linux. What I want is to find the 124660968th string – that is, the one that would have been printed next. The caveat, of course, is that I don't know the MAGICNUMBER. I'm pretty sure that it's possible to brute-force all possibilities, but it would take millennia, it seems. I've tried to snoop around in rand() source code, but I don't really understand it, much less exploit it. Is it possible to find that string in more or less reasonable time?
UPD Is it even possible to generate what is supposed to go after my string without finding out the seed?
unsigned int... – user Mar 30 '16 at 14:20cout,rand(),std::stringand so on. – user Mar 30 '16 at 14:30rand()doesn't return crypto-level results, and the mod afterwards will skew to one side (since the range of the random is not a multiple of the alphabet size). – Clockwork-Muse Mar 30 '16 at 18:32Anyway,
– Spencer D Apr 11 '16 at 21:23srand()takes an unsigned integer, so why not just search the binary or memory for the number? Once you know the MAGICNUMBER, you can easily predict what comes next because it follows a set formula to generate random numbers. However, if you are wanting to reverse the PRNG without MAGICNUMBER, using only the known outputs, I suppose it is possible, but difficult. You would need to determine the internal state when the last random number was generated