📄 fips.c
字号:
/* whn */ ILLEGAL_PAIR,
/* who */ BEGIN | NOT_END,
/* whp */ ILLEGAL_PAIR,
/* whr */ ILLEGAL_PAIR,
/* whs */ ILLEGAL_PAIR,
/* wht */ ILLEGAL_PAIR,
/* whu */ ILLEGAL_PAIR,
/* whv */ ILLEGAL_PAIR,
/* whw */ ILLEGAL_PAIR,
/* whx */ ILLEGAL_PAIR,
/* why */ BEGIN | NOT_END,
/* whz */ ILLEGAL_PAIR,
/* whch */ ILLEGAL_PAIR,
/* whgh */ ILLEGAL_PAIR,
/* whph */ ILLEGAL_PAIR,
/* whrh */ ILLEGAL_PAIR,
/* whsh */ ILLEGAL_PAIR,
/* whth */ ILLEGAL_PAIR,
/* whwh */ ILLEGAL_PAIR,
/* whqu */ ILLEGAL_PAIR,
/* whck */ ILLEGAL_PAIR,
/* qua */ ANY_COMBINATION,
/* qub */ ILLEGAL_PAIR,
/* quc */ ILLEGAL_PAIR,
/* qud */ ILLEGAL_PAIR,
/* que */ ANY_COMBINATION,
/* quf */ ILLEGAL_PAIR,
/* qug */ ILLEGAL_PAIR,
/* quh */ ILLEGAL_PAIR,
/* qui */ ANY_COMBINATION,
/* quj */ ILLEGAL_PAIR,
/* quk */ ILLEGAL_PAIR,
/* qul */ ILLEGAL_PAIR,
/* qum */ ILLEGAL_PAIR,
/* qun */ ILLEGAL_PAIR,
/* quo */ ANY_COMBINATION,
/* qup */ ILLEGAL_PAIR,
/* qur */ ILLEGAL_PAIR,
/* qus */ ILLEGAL_PAIR,
/* qut */ ILLEGAL_PAIR,
/* quu */ ILLEGAL_PAIR,
/* quv */ ILLEGAL_PAIR,
/* quw */ ILLEGAL_PAIR,
/* qux */ ILLEGAL_PAIR,
/* quy */ ILLEGAL_PAIR,
/* quz */ ILLEGAL_PAIR,
/* quch */ ILLEGAL_PAIR,
/* qugh */ ILLEGAL_PAIR,
/* quph */ ILLEGAL_PAIR,
/* qurh */ ILLEGAL_PAIR,
/* qush */ ILLEGAL_PAIR,
/* quth */ ILLEGAL_PAIR,
/* quwh */ ILLEGAL_PAIR,
/* ququ */ ILLEGAL_PAIR,
/* quck */ ILLEGAL_PAIR,
/* cka */ NOT_BEGIN | BREAK | NOT_END,
/* ckb */ NOT_BEGIN | BREAK | NOT_END,
/* ckc */ NOT_BEGIN | BREAK | NOT_END,
/* ckd */ NOT_BEGIN | BREAK | NOT_END,
/* cke */ NOT_BEGIN | BREAK | NOT_END,
/* ckf */ NOT_BEGIN | BREAK | NOT_END,
/* ckg */ NOT_BEGIN | BREAK | NOT_END,
/* ckh */ NOT_BEGIN | BREAK | NOT_END,
/* cki */ NOT_BEGIN | BREAK | NOT_END,
/* ckj */ NOT_BEGIN | BREAK | NOT_END,
/* ckk */ NOT_BEGIN | BREAK | NOT_END,
/* ckl */ NOT_BEGIN | BREAK | NOT_END,
/* ckm */ NOT_BEGIN | BREAK | NOT_END,
/* ckn */ NOT_BEGIN | BREAK | NOT_END,
/* cko */ NOT_BEGIN | BREAK | NOT_END,
/* ckp */ NOT_BEGIN | BREAK | NOT_END,
/* ckr */ NOT_BEGIN | BREAK | NOT_END,
/* cks */ NOT_BEGIN,
/* ckt */ NOT_BEGIN | BREAK | NOT_END,
/* cku */ NOT_BEGIN | BREAK | NOT_END,
/* ckv */ NOT_BEGIN | BREAK | NOT_END,
/* ckw */ NOT_BEGIN | BREAK | NOT_END,
/* ckx */ ILLEGAL_PAIR,
/* cky */ NOT_BEGIN,
/* ckz */ NOT_BEGIN | BREAK | NOT_END,
/* ckch */ NOT_BEGIN | BREAK | NOT_END,
/* ckgh */ NOT_BEGIN | BREAK | NOT_END,
/* ckph */ NOT_BEGIN | BREAK | NOT_END,
/* ckrh */ ILLEGAL_PAIR,
/* cksh */ NOT_BEGIN | BREAK | NOT_END,
/* ckth */ NOT_BEGIN | BREAK | NOT_END,
/* ckwh */ ILLEGAL_PAIR,
/* ckqu */ NOT_BEGIN | BREAK | NOT_END,
/* ckck */ ILLEGAL_PAIR
};
#ifdef RAN_DEBUG
main (argc, argv)
int argc;
char *argv[];
{
register int argno;
register long seed;
register unsigned short int pwlen;
register unsigned short int minimum;
int number_of_words;
boolean no_legal_words;
register char *unhyphenated_word;
register char *hyphenated_word;
time_t ltime;
#ifdef B1
int algorithm = 0;
#endif
number_of_words = 1;
no_legal_words = FALSE;
seed = 0L;
pwlen = 8;
minimum = 6;
for (argno = 0; argno < argc; argno++)
{
if (argv[argno][0] == '-')
switch (argv[argno][1])
{
#ifdef B1
case 'a':
algorithm = atoi (&argv[argno][2]);
break;
#endif
case 's':
seed = atol (&argv[argno][2]);
if (seed == 0L)
seed = 1L;
set_seed(seed);
break;
case 'l':
pwlen = abs (atoi (&argv[argno][2]));
if (pwlen < 1)
pwlen = 8;
break;
case 'm':
minimum = abs (atoi (&argv[argno][2]));
if (minimum < 1)
minimum = 1;
break;
case 'n':
no_legal_words = TRUE;
break;
}
else
number_of_words = atoi (argv[argno]);
if (number_of_words < 1)
number_of_words = 1;
}
/*
* During debugging (RAN_DEBUG is set), we generate the seed
from here
* rather than the first entry to randomword() .
*/
if (seed == 0L){
time(<ime);
set_seed((long) ltime);
}
if (minimum > pwlen)
{
(void) fflush(stdout);
(void) fprintf (stderr, "minimum (%u) new password length cannot exceed maximum (%u)\n", (uint) minimum, (uint) pwlen);
(void) fflush(stderr);
exit (1);
}
(void) fflush(stderr);
(void) fprintf (stdout, "(New password will be between %u and %u characters long)\n", (uint) minimum, (uint) pwlen);
(void) fflush (stdout);
for (argno = 1; argno <= number_of_words; argno++)
{
unhyphenated_word = calloc (sizeof (char), pwlen + 1);
hyphenated_word = calloc (sizeof (char), 2 * pwlen);
#ifdef B1
switch (algorithm) {
default:
case 0:
(void) randomword (unhyphenated_word, hyphenated_word,
minimum, pwlen, no_legal_words, 0L);
(void) fflush(stderr);
(void) fprintf (stdout, "%s (%s)\n", unhyphenated_word,
hyphenated_word);
break;
case 1:
(void) randomchars (unhyphenated_word, minimum, pwlen,
no_legal_words, 0L);
(void) fflush(stderr);
(void) fprintf (stdout, "%s\n", unhyphenated_word);
break;
case 2:
(void) randomletters (unhyphenated_word, minimum, pwlen,
no_legal_words, 0L);
(void) fflush(stderr);
(void) fprintf (stdout, "%s\n", unhyphenated_word);
break;
}
#else
(void) randomword (unhyphenated_word, hyphenated_word,
minimum, pwlen, no_legal_words, 0L);
(void) fflush(stderr);
(void) fprintf (stdout, "%s (%s)\n", unhyphenated_word,
hyphenated_word);
#endif
(void) fflush (stdout);
free (unhyphenated_word);
free (hyphenated_word);
}
}
#endif
#ifdef B1
/*
* Randomchars will generate a random string and place it in the
* buffer word. The word must be pre-allocated. The words
generated
* will have sizes between minlen and maxlen. If restrict is TRUE,
* words will not be generated that appear as login names or as
entries
* in the on-line dictionary. The seed is used on first use of the
routine.
* The length of the word is returned, or -1 if there were an error
* (length settings are wrong or dictionary checking could not be
done).
* The seed is used on first use of the routine.
*/
int
randomchars(string, minlen, maxlen, restrict, seed)
register char *string;
register unsigned short int minlen;
register unsigned short int maxlen;
register boolean restrict;
long seed;
{
register int loop_count;
register unsigned short int string_size;
register unsigned short int build;
static been_here_before = FALSE;
/*
* Execute this upon startup. This initializes the
* environment, including seed'ing the random number
* generator and loading the on-line dictionary.
*/
if (!been_here_before)
{
been_here_before = TRUE;
#ifndef RAN_DEBUG
set_seed(seed);
#endif
}
/*
* Check for minlen > maxlen. This is an error.
*/
if (minlen > maxlen)
return (-1);
loop_count = 0;
string_size = get_random(minlen, maxlen);
do {
for (build = 0; build < string_size; build++) {
string[build] = (char) get_random((unsigned short
int) '!',
(unsigned short int) '~');
}
restrict = 0;
loop_count ++;
}
while (restrict && (loop_count <= MAX_UNACCEPTABLE));
string[string_size] = '\0';
return string_size;
}
/*
* Randomletters will generate a random string of letters and place
it in the
* buffer word. The word must be pre-allocated. The words
generated
* will have sizes between minlen and maxlen. If restrict is TRUE,
* words will not be generated that appear as login names or as
entries
* in the on-line dictionary. The seed is used on first use of the
routine.
* The length of the word is returned, or -1 if there were an error
* (length settings are wrong or dictionary checking could not be
done).
* The seed is used on first use of the routine.
*/
int
randomletters(string, minlen, maxlen, restrict, seed)
register char *string;
register unsigned short int minlen;
register unsigned short int maxlen;
register boolean restrict;
long seed;
{
register int loop_count;
register unsigned short int string_size;
register unsigned short int build;
static been_here_before = FALSE;
/*
* Execute this upon startup. This initializes the
* environment, including seed'ing the random number
* generator and loading the on-line dictionary.
*/
if (!been_here_before)
{
been_here_before = TRUE;
#ifndef RAN_DEBUG
set_seed(seed);
#endif
}
/*
* Check for minlen > maxlen. This is an error.
*/
if (minlen > maxlen)
return (-1);
loop_count = 0;
string_size = get_random(minlen, maxlen);
do {
for (build = 0; build < string_size; build++) {
string[build] = (char) get_random((unsigned short
int) 'a', (unsigned short int) 'z');
}
restrict = 0;
loop_count ++;
}
while (restrict && (loop_count <= MAX_UNACCEPTABLE));
string[string_size] = '\0';
return string_size;
}
#endif
/*
* Randomword will generate a random word and place it in the
* buffer word. Also, the hyphenated word will be placed into
* the buffer hyphenated_word. Both word and hyphenated_word must
* be pre-allocated. The words generated will have sizes between
* minlen and maxlen. If restrict is TRUE, words will not be
generated that
* appear as login names or as entries in the on-line dictionary.
* This algorithm was initially worded out by Morrie Gasser in
1975.
* Any changes here are minimal so that as many word combinations
* can be produced as possible (and thus keep the words random).
* The seed is used on first use of the routine.
* The length of the unhyphenated word is returned, or -1 if there
* were an error (length settings are wrong or dictionary checking
* could not be done.
*/
int
randomword (word, hyphenated_word, minlen, maxlen, restrict, seed)
register char *word;
register char *hyphenated_word;
register unsigned short int minlen;
register unsigned short int maxlen;
register boolean restrict;
long seed;
{
register int pwlen;
register int loop_count;
static been_here_before = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -