① c语言密码
用什么替换?
暂时用小写加移位取?比如A加密成c,B加密成d,就是大写变小写后位置发生变化。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void EncodeString(char *str,int key)
{
int length,i;//length为传入字符串长度,i用作循环计数器
length=strlen(str);
for(i=0;i<length;i++)//对字符串中的每个字符依次进行加密
{
if(isupper(str[i]))//对大写字母加密
{
str[i]+=key%26;
if(str[i]>'Z')
{
str[i]-=26;
}
else if(str[i]<'A')
{
str[i]+=26;
}
}
else if(islower(str[i]))//对小写字母加密
{
if(str[i]+key%26<128){
str[i]+=key%26;
if(str[i]>'z')
{
str[i]-=26;
}
else if(str[i]<'a')
{
str[i]+=26;
}
}
else{str[i]-=26;str[i]+=key%26;}
}
}
}
void main()
{
char arr[50],buffer;//arr[50]用来接收字符串信息,buffer用来接收缓冲区中的回车
int key;//key为加密秘钥
printf("This program encodes messages using a cyclic cipher.
");
printf("To stop, enter 0 as the key.
");
while(1)//程序一直运行,直到输入密钥0为止
{
printf("Enter the key: ");
scanf("%d",&key);
scanf("%c",&buffer);
if(0==key)
{
break;//输入密钥为0,则退出程序
}
printf("Enter a message: ");
scanf("%s",arr);
scanf("%c",&buffer);
EncodeString(arr,key);
printf("Encoded message: %s
",arr);
}
}
② 帮忙用C语言写一个密码
#include <stdio.h>
#define MAX_LENGTH 128
#define FILE_NAME "pwd.dat"
#define INIT_PWD "123456"
char pwd[MAX_LENGTH+1];
void Init ( void )
{
FILE *fp;
fp = fopen ( FILE_NAME, "r" );
if ( fp == NULL )
{
strcpy ( pwd, INIT_PWD );
}
else
{
fgets ( pwd, MAX_LENGTH, fp );
fclose ( fp );
}
}
void Login ( void )
{
char ch;
char tmp[MAX_LENGTH+1];
int pass = 1;
while ( pass )
{
puts ( "==================================\nPlease input your password!" );
scanf ( "%s", tmp );
pass = strcmp ( tmp, pwd );
}
}
void Edit ( void )
{
puts ( "Please input a new password!" );
scanf ( "%s", pwd );
}
void End ( void )
{
FILE *fp;
fp = fopen ( FILE_NAME, "w" );
if ( fp == NULL )
{
printf ( "Cannot save your password!\n" );
system ( "pause" );
}
else
{
fputs ( pwd, fp );
fclose ( fp );
}
}
int main ( void )
{
Init();
Login();
Edit();
End();
}
③ 悬赏100分 如何用c语言 写一个密码程序
clude "string.h"
//考虑到用数据库文件保存注册信息的话要使用access创建文件并且还要配置数据源,所以我的方法是采用将注册信息保存到文件
//下面是完整的程序:
//登陆检测函数
int login(char *name,char *password)
{
char info[10000];
char *p=info;
FILE *file=fopen("user","r");
int size;
if(file)
{
size=fread(info,1,10000,file);
while(size!=(int)p-(int)info)
{
if(!strcmp(p,name)&&!strcmp(p+strlen(p)+1,password))
{
fclose(file);
return 1;
}
p+=strlen(p)+1;
p+=strlen(p)+1;
}
}
fclose(file);
return 0;
}
//添加注册信息入文件
void save(char *name,char *password)
{
FILE *file=fopen("user","a");
fwrite(name,1,strlen(name)+1,file);
fwrite(password,1,strlen(password)+1,file);
fclose(file);
}
#define PASSWORD "12345" //这里指定你要允许通过的密码,比如12345,将引号里的数字改为你想要的即可
int main()
{
char password[100];
char name[100],c[100],password1[100];
tag1: printf("press 1 to register, or 2 to login\n");//输入1为注册,输入2为登陆
while(1)
{
gets(c);
if('1'==c[0])
{
printf("please enter your name\n");//输入姓名
gets(name);
tag2: printf("please enter your password\n");//输入密码
gets(password);
printf("please enter your password again\n");
gets(password1);
if(strcmp(password,password1))
{
//两次密码不一致,重输
printf("the password you entered is different from the first one,please try again!\n");
goto tag2;
}
printf("register is completed!\n");//注册成功
//下面实现将注册信息加入文件保存
save(name,password);
goto tag1;
}
else if('2'==c[0])
{
tag3: printf("please enter your name:\n");
gets(name);
printf("please enter your password:\n");
gets(password);
if(login(name,password))//如果验证通过,则
{
printf("login successfully!\n");
//这里添加成功登陆后要执行的代码
}
else
{
printf("your name or password doesn't exist!\n");//否则重输
goto tag3;
}
}
else
{
printf("invalid input!press 1 to register, or 2 to login\n");//输入非法,重输
goto tag1;
}
}
return 0;
}
饿,写了我两个小时啊,大哥,分一定要给我啊~~~~~~
④ c语言 密码电文
不好意思,刚才写的程序有点错误:现更正如下:(请编译人员不要删除!)
#include <stdio.h>
#include <string.h>
#define N 100
void main()
{
char s[N];
int i;
int a;
printf("Input String:");
scanf("%s",s);
for(i=0;i<=strlen(s);i++)
{
if(s[i]>='A'&&s[i]<='Z')
s[i]=26-s[i]+64+1+64;
else if(s[i]>='a'&&s[i]<='z')
s[i]=26-s[i]+96+1+96;
}
printf("%s\n",s);
}
⑤ c语言 密码电文
不好意思,刚才写的程序有点错误:现更正如下:(请编译人员不要删除!)
#include <stdio.h>
#include <string.h>
#define N 100
void main()
{
char s[N];
int i;
int a;
printf("Input String:");
scanf("%s",s);
for(i=0;i<=strlen(s);i++)
{
if(s[i]>='A'&&s[i]<='Z')
s[i]=26-s[i]+64+1+64;
else if(s[i]>='a'&&s[i]<='z')
s[i]=26-s[i]+96+1+96;
}
printf("%s\n",s);
}
⑥ 如何用C语言编写密码程序
1、用一个字符数组来存密码
再用一个字符数组接收你的输入,然后用strcmp
来比较,如果返回0则密码是正确的
2、例程:
#include"stdio.h"
#include"string.h"
intmain()
{
charmima[100]="YuanShi888";
charinput[100]={0};
printf("请输入密码:");
gets(input);
if(strcmp(mima,input)==0)
printf("恭喜你,密码正确! ");
else
printf("对不起,密码输入错误! ");
}
⑦ 请问,用C语言如何实现密码输入
c语言中可采用getch()函数来实现输入密码字符时,不显示字符到终端上,这时,只需要显示出一个相应的*就可以达到效果了。参考代码及运行效果如下图:
⑧ 密码文 编程 c语言 输入一个英文单词 将单词翻译成密码文 规则是把所有字母用它后面的第三个字母替换
#include <stdio.h>
int main()
{
char c;
while((c=getchar())!='\n'&&c!=EOF)
printf("%c", c>='a'&&c<='y'||c>='A'&&c<='Z'?c+3:c=='z'||c=='Z'?c-23:c);
printf("\n");
return 0;
}
希望楼主及时采纳,谢谢