密码生成器

/*++

Copyright (c) 2007 YourCompany

Module Name:

    <new>

Abstract:

    密码生成器:密码产生输出到文件
        对产生的密码排序,输出到文件(未实现)
        对四个1000 000 的文件合并(未实现)
Author:

    YourName (YourEmail) 2007-06-08

Revision History:

--
*/


#include
< stdio.h >
#include
< stdlib.h >
#include
< string .h >
#include
< assert.h >

#define  NUM 30    // 密码串的产生个数
#define  CIPHER_LEN 20   // 一个密码串的最大长度


 
/*++

Description: Produ_cipher()
Function    :密码产生函数  
Arguments   :char filename[]-->输入文件名
Return Value:none

--
*/


void  Produ_cipher( const   char   * filename)    
{
    
int i,j;
    
int seed;
    FILE 
*fp;
    
char a[CIPHER_LEN+1];
    
//memset(a,0,CIPHER_LEN);  //??数组建立的时候自动初始化为0不用初始??
    
    
if((fp=fopen(filename,"w"))==NULL)
        
{
            printf(
"can not open the file");
            exit(
0);
        }

    
for(j=NUM;j>0;j--)
        
{
           
for(i=0;i<CIPHER_LEN;i++)        //密码长度为CIPHER_LEN
            {
                seed
=rand()%3;
               
// if(seed>3) abort();
                switch(seed)    
                
{
                    
case 0: a[i]=(char)( rand()%26+'a');break;
                    
case 1: a[i]=(char)( rand()%26+'A');break;
                    
case 2: a[i]=(char)( rand()%10+'0');break;
                    
default :  printf("this is error ");
                }

            }

            a[CIPHER_LEN]
='/0';
            printf("%s/n",a);
            fwrite(a,CIPHER_LEN,1,fp);
            //printf("the cipher%s written into file successfully /n",a);
        }
        printf("the cipher written into file successfully /n");
    fclose(fp);
    //printf("--------------------------------------------/n");
    //In_file(a[MS]);
}
/*++
Description:main(int argc, char* argv[])
Function   :主函数
Arguments:
    默认文件名:mimatxt
Return Value:none
--*/
int main(int argc, char* argv[]) //主函数部分
{
    char *filename="mimatxt";
    printf("--------------------------------------------/n");
    printf("Function:Generate cipher : /n");
    printf("Remark  :Generate quility is NUM=30 /n");
    printf("Remark  :The length of cipher is CIPHER_LEN=20 /n");
    printf("Remark  :Ddfult file name is mimatxt /n");
    printf("--------------------------------------------/n");
    //filename={'m','i','m','a','t','x','t'};
    //printf("please input the file name:/n");
    //scanf("%s",filename);
    Produ_cipher(filename);
    return 0;
}
//问题:怎么在定义文件名的时候选择路径呢?
//对产生的密码排序??? 怎么个思路呢? 呵呵,要再想想
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值