c语言实现密码加密

Python010

c语言实现密码加密,第1张

unsigned char* encrypt(unsigned char* psw, int enc) {

int sum = 0, i

if (enc) {

for (i = 0 i < 6 i++) {

psw[i] -= 15

sum += psw[i]

}

psw[6] = (unsigned char) sum

psw[7] = 0

    }

else {

for (i = 0 i < 6 i++) {

sum += psw[i]

psw[i] += 15

}

if ((unsigned char)sum != psw[6]) {

printf("Bad password\n")

psw[0] = 0

return psw

}

else {

psw[6] = 0

}

}

for (i = 0 i < 3i++) {

unsigned char t = psw[i]

psw[i] = psw[5-i]

psw[5-i] = t

}

return psw

}

int main()

{

unsigned char psw[128]

scanf("%s", psw)

printf("encode to:%s\n", encrypt(psw, 1))

printf("decode to:%s\n", encrypt(psw, 0))

return 0

}

这个简单

 

这就就是加密函数

int password()

{

int n=0,a=0

char mi1[80]

int i=0,a1,a2,a3

int index=0,m=0

char str[30]

char user[12]

do{

 printf("\n\t************************how are you*****************************\n\n\n")

 printf("\t\tplease input the username:")

 scanf("%s",user)                  

 a1=strcmp(user,"20085126")

 if(a1==0)

 {

  FILE *f1

  if((f1=fopen("1mi.txt","rt"))==NULL) 

  { 

   printf("Cannot open file strike any key exit!")       

   exit(0)

  }

  rewind(f1)//重定向文件内部指针将文件内部的位置指针重新指向一个流(数据流/文件)的开头

  fgets(mi1,7,f1)

  

  do{

   printf("\n\t\tplease input the password:")

   scanf("%s",str)

   printf("\n")

   if(!strcmp(str,user))              /*比较密码是否一样*/

    m=1

   

   index++

   if(index>3)

   {

    printf("\n\t*****************************************************\n\n")

    printf("\t\tThe error number is more than three times while input the password, exit system!\n")

    printf("\n\t*****************************************************\n\n\n")

    return 0

   }

   

  }while(m==0)

  fclose(f1)

  }

}

}

睿尔科技

更新学习资料

http://weibo.com/cdreer