Skip to content

Instantly share code, notes, and snippets.

@harlanhaskins
Created January 11, 2016 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harlanhaskins/a22a30c1df92ea882316 to your computer and use it in GitHub Desktop.
Save harlanhaskins/a22a30c1df92ea882316 to your computer and use it in GitHub Desktop.
//
// main.c
// randomseed
//
// Created by Harlan Haskins on 1/10/16.
// Copyright © 2016 Harlan. All rights reserved.
//
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void testseed(uint32_t seed, size_t len, char *res) {
srand(seed);
for (size_t i = 0; i < len; i++) {
res[i] = (char)rand();
}
}
int main(int argc, const char * argv[]) {
if (argc < 2) {
puts("Usage: randomseed [string]");
return EXIT_FAILURE;
}
size_t len = strlen(argv[1]);
char *res = calloc(sizeof(char), len);
int found = 0;
uint32_t seed = 0;
while (seed < UINT32_MAX) {
testseed(seed, len, res);
// printf("[%u]: %s\n", seed, res);
if (strncmp(res, argv[1], len) == 0) {
found = 1;
break;
}
seed++;
}
if (found) {
printf("Seed found! %u\n", seed);
printf("Res: %s, String: %s\n", res, argv[1]);
} else {
printf("No seed found for %s", argv[1]);
}
free(res);
return 0;
}
@harlanhaskins
Copy link
Author

Will find a seed for the libc random number generator that generates whatever string you give it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment