这就就是加密函数
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
#include "stdio.h"int* set(void)
int* set(void)
{
int i
static a[4]
printf("请输入要设置的4位密码 :")
for(i=0i<4i++)
{
scanf("%d",&a[i])
}
return a
}
int main()
{
int i,*a,b[4]
a=set()
printf("请输入4位密码 :")
for(i=0i<4i++)
{
scanf("%d",&b[i])
}
i=0
while(i<4)
{
if(a[i]==b[i])
{
printf("%d",a[i])
i++
}
else
{
break
}
}
if(i==4)
{
printf("密码正确\n")
}
else
{
printf("密码错误\n")
}
return 0
}
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
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)