Created
January 11, 2016 19:28
-
-
Save harlanhaskins/a22a30c1df92ea882316 to your computer and use it in GitHub Desktop.
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
// | |
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will find a seed for the
libc
random number generator that generates whatever string you give it.