① 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;
}
希望樓主及時採納,謝謝