Crane
Table_bottom

Search
Loading
Table_bottom

分类
Table_bottom

随机文章
Table_bottom

标签云
Table_bottom

最新评论
Table_bottom

链接
Table_bottom

功能
Table_bottom

15身份证号码转18位的程序

Crane posted @ 2010年4月09日 13:56 in Programing with tags c 编程 , 6488 阅读

以前在哪看到的,安全焦点吧!丢这做个备份

 

/*输入原来的15位身份证号码,产生新的18位身份证号码的程序*/

#include "stdio.h"
#include "string.h"
#include "conio.h"

/*
* gen New 18 ID Card from old 15 ID
*/
char genNewID( char ID[], char NewID[])
{
    int W[18] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1};
    char A[11] = {'1','0','x','9','8','7','6','5','4','3','2'};
    int i,j,S;

    if(strlen(ID) != 15)
        return -1;

    memcpy( NewID, ID, 6 );
    NewID[6]='1';
    NewID[7]='9';
    NewID[8]=0;
    strcat( NewID, &ID[6] );
    S = 0;
    for(i=0;i<17;i++)
    {
        j = (NewID[i] - '0') * W[i];
        S = S + j;
    }

    S = S % 11;
    NewID[17] = A[S];
    NewID[18] = 0;

    return A[S];
}

int main(int argc, char* argv[])
{
    char ID[20], NewID[20], ret;

    puts("输入原来的15位身份证号码,产生新的18位身份证号码\n");
    do{
        printf("Input your old 15 ID Card: ");
        scanf( "%s", ID );
        if(stricmp(ID, "exit") == 0)break;
        ret = genNewID( ID, NewID );
        printf("Your New 18 ID Card:       %s \n", ret != -1 ? NewID : "Input Error!!");
    }while(1);

    getch();

    return 0;
} 

 

 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter