#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include<string.h>
void encryption(int x,char *epin,char key)
{
char cpin[200];
int i=0;
srand(time(0));
key=rand()%94+'!';
for(i=0;i<x;i++)
{
do{
epin[i]=cpin[i]^key;
}while(epin[i]<'!');
}
}
int main()
{
int x=0,i1=0;
char cpin[200],epin[x],key;
getchar();
printf("please input your password:");
while((cpin[x] = getchar())!='\n')
{
x=x+1;
}
printf("your length of password is %d\n",x);
encryption(x,epin,key);
printf("your key is %c\n",key);
printf("your encrypted password is ");
for(i1=0;i1<x;i1++)
{
printf("%c",epin[i1]);
}
return 0;
}
我写了一个按位异或加密的程序,密钥key的值不能在主函数中输出,加密密码cpin也不能正常显示,想知道怎么解决,可以给一个代码吗
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- CSDN专家-link 2021-11-23 15:27关注
void encryption(int x,char *epin,char *cpin,char *key) { int i=0; *key=rand()%94+'!'; for(i=0;i<x;i++) { epin[i]=cpin[i]^*key; if(epin[i]<'!') { i=0; *key=rand()%94+'!'; } } } int main() { int x=0,i1=0; char cpin[200],epin[200],key; srand(time(0)); getchar(); printf("please input your password:"); while((cpin[x++] = getchar())!='\n') { // x=x+1; } printf("your length of password is %d\n",x); encryption(x,epin,cpin,&key); printf("your key is %c\n",key); printf("your encrypted password is "); for(i1=0;i1<x;i1++) { printf("%c",epin[i1]); } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
- ¥500 52810做蓝牙接受端
- ¥15 基于PLC的三轴机械手程序
- ¥15 多址通信方式的抗噪声性能和系统容量对比
- ¥15 winform的chart曲线生成时有凸起
- ¥15 msix packaging tool打包问题
- ¥15 finalshell节点的搭建代码和那个端口代码教程
- ¥15 Centos / PETSc / PETGEM
- ¥15 centos7.9 IPv6端口telnet和端口监控问题
- ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作