用C语言设计一个加密 解密 密码 的程序。
// playFair 加密 你参考下 ... #include"stdio.h"#include"string.h"#include"stdlib.h"#define x 50 char MiYao[x],PassWord[x],AddPass[x],Table[5][5],Map[25]; bool Visit[27]={false}; char English[27]="abcdefghijklmnopqrstuvwxyz"; void Input() { printf("请输入密钥:\t"); scanf("%s",MiYao); printf("请输入待加密密码:\t"); scanf("%s",PassWord); } void Fun_5x5() { int count = 0,V =0; /*标记密钥内字符为: true*/ for(int i=0;MiYao[i]!='\0';i++) if(strchr(English,MiYao[i])!=NULL) Visit[strchr(English,MiYao[i])-English] = true; /*执行密钥矩阵操作 并标记已使用字符:true*/ for(int i=0;i for(int j=0;j { if(count Table[i][j] = MiYao[count++]; else { while(Visit[V] != false) V++; Table[i][j] = English[V]; Visit[V++] = true; } } puts("∞∞∞密钥矩阵为∞∞∞"); for(int i=0;i { for(int j=0;j printf("%3c",Table[i][j]); puts(""); } puts("∞∞∞∞∞∞∞∞∞∞∞"); } int IsVisited(char ch) { return Visit[strchr(English,ch)-English]; //false 未出现过 } void TabletoMap() { int count=0; for(int i=0;i for(int j=0;j Map[count++]=Table[i][j]; Map[count]='\0'; } void Judge() { int len = strlen(PassWord),i,j,k; memset(AddPass,0,sizeof(char)); /*一对对去字母,剩下单个字母,则不变化,直接放入加密串中.*/ if(len%2){ AddPass[len-1] = PassWord[len-1]; len -=1; } /*一对中 密钥矩阵中 存在矩阵 eg.ab 先输出a同行顶点在输出b同行顶点*/ int row1,low1,row2,low2,a1,a2; for(i=0;i { char c1,c2; c1 = PassWord[i]; c2 = PassWord[i+1]; /*一对中 两字母相同 无变化*/ /*一对中 有字母不在密钥矩阵中 无变化*/ if(c1 == c2 || ( !IsVisited(c1)||!IsVisited(c2))) { AddPass[i] = c1; AddPass[i+1]=c2; }else{ a1 = strchr(Map,c1)-Map; row1 = a1/5; low1 = a1%5; a2 = strchr(Map,c2)-Map; row2 = a2/5; low2 = a2%5; /*一对中 字符出现在同行或同列 简单swap字符*/ if(row1 == row2 || low1 == low2) { AddPass[i] = c2; AddPass[i+1] = c1; }else{ AddPass[i] = Table[row1][low2]; AddPass[i+1] = Table[row2][low1]; } } }AddPass[len+1]='\0'; puts("加密后字符串:"); puts(AddPass); puts("原串是:"); puts(PassWord); } int main() { Input(); Fun_5x5(); TabletoMap(); Judge(); return 0; }
【在线等…!!!】用C语言写一个密码程序
//---------------------------------------------------------------------------#include #include #include #define PFE "pas.dat" /*保存密码的文件*/#define DEFPAS "123456" /*初始密码*/void setpass(void){FILE *fp=NULL;char pas[20];printf("是否设置新密码?(Y/N):");fflush(stdin);if (tolower(getchar())=='y') {printf("请输入新密码:\n");scanf("%20s",pas);fp=fopen(PFE,"wb");fwrite(pas,sizeof(char),strlen(pas),fp);fclose(fp);printf("已经设置新密码,下次请使用新密码登录\n");}fflush(stdin);}int main(void){FILE *pf;char pass[20]=DEFPAS,ch[20];if (pf=fopen(PFE,"rb")) {fread(pass,sizeof(char),20,pf);fclose(pf);}printf("请输入密码:");scanf("%s",ch);if (!strcmp(ch,pass)) {printf("登录成功\n");setpass();printf("欢迎使用本系统\n");getchar();}else printf("密码错误,登录失败!\n");return 0;}//---------------------------------------------------------------------------
C语言中密码输入问题!C语言中如何实现输入密码?(在输入时显示...
你说是用标准C吧? 这个问题很是新颖,我也费了番工夫去想。
因为在C语言中不像VC与VB等可视化的编译系统,他好像没有提供这种函数(我没有找到) 我想有一种方法可以大概的实现它。
用fo 语句和getch( );putcha ('*');来实现的,而getch 不分区另ENTER和BACKSPACE等特殊键,不好控制它的结束。
因此只有避过问题强行规定密码必须是8位的,但在输入密码时仍然不允许用户输入ENTER和BACKSPACE等特殊键。
我已用这种方法试验过,结果与问题正如上面所述。
你也不妨一试。
c语言password是什么意思
#include#include#include#include#include#include#include#include#include#include#include#include#include#includeint mima(int az);int main(){system("md pass");system("cls");coutcoutcoutcoutcoutcoutcoutcoutcoutcoutcoutint jh=0;mima(jh);return 0;}int mima(int az){if(az==3){coutcoutcoutsystem("pause");return 0;}coutcoutstring mimaa;coutcin>>mimaa;if(mimaa=="end"){return 0;}if(mimaa!="1q2w3e"){++az;coutcoutcoutcoutmima(az);}else{coutcoutcoutcoutsystem("pause");system("cls");cout}return 0;} LZ 呃,我只会C++,凑合着看吧刚才楼下的,为了学习方便 所以全写上去了 啊哈哈~~~楼上挺有趣的,其实你也不差的~~
C语言的密码翻译程序
main() {char *str="aabbcc112546XXXyyyzzz";//密码printf("密码:%s\n",str);//解密printf("原文:");int i=0;while(str[i]!='\0'){if(str[i]>64&&str[i]{printf("%c",(26-(str[i]-64)+1)+64);i++;continue;}if(str[i]>96&&str[i]{printf("%c",(26-(str[i]-96)+1)+96);i++;continue;}printf("%c",str[i]);i++;}printf("\n");}
C语言怎么使用密码输入,也就是输入回显星号。
用for 语句和getch( );putchar ('*');来实现的,而getch 不分区另ENTER和BACKSPACE等特殊键,不好控制它的结束。
因此只有避过问题强行规定密码必须是8位的,但在输入密码时仍然不允许用户输入ENTER和BACKSPACE等特殊键。
以下程序功能: 接受所有打印字符。
不接受控制字符,如Ctrl+ ,Alt,F1等。
可使用退格键删除以输入字符。
回车键为密码输入完毕 可定义最大字符数。
当输入字符数等于最大字符个数时,视为密码结束。
#include #include #define TRUE 1 #define FALSE 0 #define MIN_INPUT 0x20 #define MAX_INPUT 0x7e /* * 所有功能有此函数实现: * pszPw : 保存密码的缓冲 * iMaxSize :最大的密码长度,该长度必须小于缓冲区大小。
* 返回值为TRUE为成功获取密码。
总是返回TRUE */ int GetPassword(unsigned char* pszPw,int iMaxSize) { unsigned char ch; int i=0; int bIsEcho=TRUE; //while( ! kbhit() && iwhile( ( ch = (unsigned char)getch() ) && i { //ch = (unsigned char)getch(); bIsEcho=TRUE; if ( ch == 13) { pszPw[i++]=0; break; } else if ( ch >= MIN_INPUT && ch { pszPw[i++]=ch; } else if ( ch == 8 && i>0 ) /*退格键*/ { pszPw[i--] = 0; bIsEcho = FALSE; putchar( ch ); putchar( ' ' ); putchar( ch ); } else bIsEcho = FALSE; if(bIsEcho) putchar('*'); } pszPw[i]=0; return TRUE; } int main(void) { int iMaxSize=80; unsigned char pw[99]; if ( GetPassword(pw,iMaxSize) == TRUE ){ printf("\npassword=%s",pw); } else{ printf("\nCan not get the password!"); } }
c语言由文本文件password.dat中读取到如下数据
/* 建立一个password.dat文件,用文本方式打开,将数据集输入,放在程序目录下 */#include "stdio.h"#include "stdlib.h"void main(){ FILE *fp;int i=0,add=0;char str[200],str1[101]={0}; /* str1是需要保存的字符 */if((fp=fopen("password.dat","rt"))==NULL) /* 打开程序目录下已经编辑的文件 */{printf("cannot open file\n");return;}while (fgets(str,200,fp)) //读取一行,并判断文件是否结束{add++;if(add%3==2) str1[i++]=str[0];}fclose(fp);printf("%s\n",str1);}
C语言 怎样用C语言实现密码输入与确认的效果。
1、用一个字符数组来存密,再用一个字符数组接输入,然后用strcmp来比较,如果返回0则密码是正确的。
2、例程:#include "stdio.h"#include "string.h"int main(){char mima[100]="YuanShi888";char input[100]={0};printf("请输入密码:");gets(input);if(strcmp(mima,input)==0)printf("恭喜你,密码正确!\n");elseprintf("对不起,密码输入错误!\n");return 0;}
转载请注明出处51数据库 » c语言password