void main()
{
int a[5] /* 存储各位上的数字 */
int num, temp, encripy/* num是要输入的数,temp是交换时用来存储临时值,encripy是加密后的数据 */
int i
do
{
printf("Please input the number:")
scanf("%d",&num)
if(!(num/10000 !=0 &&num/100000==0))
printf("Data error!\n")
}while(!(num/10000 !=0 &&num/100000==0))
a[0] = num/10000%10/* 求各位上的数字 */
a[1] = num/1000%10
a[2] = num/100%10 /* 百位上的数字 */
a[3] = num/10%10/* 十位上的数字 */
a[4] = num%10 /* 个位上的数字 */
for(i = 0i <5++i) /* 开始加密 */
a[i] = (a[i] + 8)%10
temp = a[0] /* 交换位置开始 */
a[0] = a[3]
a[3] = temp
temp = a[1]
a[1] = a[2]
a[2] = temp /* 交换位置结束同时加密结束 */
encripy = a[0]*10000 + a[1]*1000 + a[2]*100 + a[3]*10 + a[4] /* 加密后的数据 */
printf("\nThe scourse number: %d\n", num)/* 输出原数据 */
printf("\nEncripy the number: %d\n\n", encripy) /* 输出加密后的数据 */
}
在VC6.0成功运行,希望对你有帮助!
#include<stdio.h>#define
N
8
void
main()
{
int
code,count,i,temp
int
key[N]
printf("请输入密码:")
scanf("%d",&code)
//各位交换
i=0
count=0
while(code!=0)
{
key[i]=code%10
code
/=
10
i++
count++
}
//各位
加5,并对其取余
for(i=0i<counti++)
{
key[i]
+=
5
key[i]
%=
10
}
//数字第一位与最后一位互换
temp
=
key[0]
key[0]
=
key[count-1]
key[count-1]
=
temp
for(i=0i<counti++)
{
printf("%d
",key[i])
}
}
//晕...你是北大青鸟的吧..我昨天刚做了这个项目.刚好发给你了..
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条)