un script en c pour générer des mots de passe
source: http://forum.ubuntu-fr.org/viewtopic.php?id=246040 (la source contient plein de caractères supplémentaires)
// Random ASCII password generator
// Compile it with g++
// Run it as ./name_of_the program length_desired
#include <cstdlib>
#include <iostream>
#include <climits>
#include <ctime>
const char ascii_table[] = {
'0', '1', '2', '3',
'4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c',
'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z'
};
int main(int argc, char ** argv)
{
if (argc == 1 || !atoi(argv[1])) return EXIT_FAILURE;
int numChars = sizeof(ascii_table) / sizeof(ascii_table[0]);
srand(time(NULL)+getpid());
for (unsigned int i = 0; i < atoi(argv[1]); ++i) {
int k = (int) ((double)numChars * (rand() / (RAND_MAX + 1.0)));
std::cout << ascii_table[k];
}
std::cout << std::endl;
return EXIT_SUCCESS;
}