當前位置:首頁 » 編程語言 » c語言兩位數密碼的程序代碼
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言兩位數密碼的程序代碼

發布時間: 2022-05-09 01:26:28

⑴ 一個兩位純數字密碼破解程序怎麼編,用c語言

1、數據范圍小的密碼可以使用窮舉法。這里從00到99,當作字元來處理,需要兩重循環。

2、常式:

chara,b,c='1',d='2';//這里變數c,d表示密碼的第一位和第二位。
charkey[2];
for(a='0';a<='9';a++){
for(b='0';b<='9';b++){
key[0]=a;
key[1]=b;//這就是一個密碼
if(key[0]==c&&key[1]==d)printf("密碼是:%s",key);//找到密碼並輸出
}
}

⑵ 密碼鎖c語言編程代碼

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
intmain()
{
charpassword[10],password2[10];
memset(password,0,sizeof(password));
memset(password2,0,sizeof(password2));
printf("請設置8位數以內密碼: ");
scanf("%s",password);
printf("請設置校驗密碼: ");
scanf("%s",password2);
if(atoi(password2)==atoi(password))
{
printf("密碼輸入正確!: ");
}
else
{
printf("密碼輸入錯誤!: ");
}
return0;
}

⑶ c語言 修改密碼初始密碼為123456,密碼包含數字和字母,數字必須大於2位

#include<stdio.h>
#include<string.h>
#include<ctype.h>
intmain()
{charpsw[21]="123456",t1[21],t2[21];
inti,n=0;
printf("請輸入初始密碼: ");
do
{gets(t1);
n++;
err=strcmp(t1,psw);
if(err)printf("初始密碼錯誤!請重新輸入! ");
}
while(err&&n<3);
if(strcmp(t1,psw))
{printf("密碼錯誤,不能登錄! ");
return0;
}
while(n<3)
{while(n<3)
{printf("請輸入新密碼: ");
gets(t1);
for(i=0;t1[i];i++)
if(isdigit(t1[i]))n++;
if(n<3)
{n=0;
printf("數字必須大於2位! ");
}
}
printf("請再次輸入新密碼: ");
gets(t2);
if(strcmp(t1,t2)==0)
printf("密碼修改成功! ");
else
{printf("二次密碼不一致! ");
n=0;
}
}
return0;
}

⑷ 如何用c語言來編一個簡單的密碼程序

這個問題很難解釋啊~如果最簡單的說,你有一個固定的密碼,比如123
那麼直接就是
if(password==123){
//你要輸出的正確信息,比如cout
?????????
}
else{
//錯誤信息
}
復雜來說,你的密碼可能存放在一個資料庫中,你就要先在資料庫中查找對應的用戶名,再核對密碼
此外,密碼一般是不能直接保存的,會被看到,所以你要有個加密的演算法來保存你的密碼,簡單來說,你把正確的密碼加密後保存,你等他輸入一個密碼,你用同樣的演算法加密,再和你的保存的加密過的比較就OK了

⑸ 如何用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語言做一個輸入密碼程序

以gcc編譯器為例,可以分為四步。
第一步是預處理,包括語法檢查等工作。
gcc
-p
abc.c
第二步由源程序生產匯編語言代碼。
gcc
-s
abc.c
會生成abc.s文件,這個文件里就是匯編代碼。
第三步編譯器生成目標代碼,一個源文件生成一個目標代碼。
gcc
-c
abc.c
會生成abc.o
第四步連接器從目標代碼生成可執行文件。
gcc
abc.o
目標代碼包括機器碼和符號表(函數及變數名)。連接器的主要作用是通過符號表在庫文件和其他模塊中找到在目標代碼中引入或未定義的符號(函數及變數名),將幾個目標代碼合成可執行文件。

⑺ 如何使用c語言編寫一個密碼程序

密碼保存在文件中,從文件中讀取密碼,但是沒做容錯和異常處理,僅供參考

#include <stdio.h>
#include <string.h>

#define PSDLEN 6

void inputPsd(char *str) /*處理輸入*/
{
int i;

for(i = 0; i < PSDLEN; i++)
{
while(1)
{
str[i] = getch();
if(str[i] == '\b') /*處理退格鍵*/
{
i--;
if(i < 0)
{
i = 0;
}
else
{
printf("\b \b");
}
continue;
}
else if(str[i] == '\r') /*處理回車鍵*/
{
continue;
}
else
{
printf("*");
break;
}
}
}
str[i] = '\0';
printf("\n");
}

int checkFirst() /*檢測是否是第一次使用*/
{
FILE *fp;
if((fp = fopen("psd.dat", "rb")) == NULL)
{
return 1;
}
fclose(fp);
return 0;
}

void firstUse() /*第一次使用 需要輸入密碼*/
{
FILE *fp;
int i;
char passwd[PSDLEN + 1];
char checkPsd[PSDLEN + 1];

if((fp = fopen("psd.dat", "wb")) == NULL)
{
printf("Creat password error!\n");
exit(1);
}
while(1)
{
printf("Please input password:");
inputPsd(passwd);

printf("\nPlease input password again:");
inputPsd(checkPsd);

if(!strcmp(passwd, checkPsd))
{
break;
}
printf("\ncheck password error! \n");
}
fwrite(passwd, sizeof(char), PSDLEN, fp);
fclose(fp);
}

void login() /*核對密碼,並登錄*/
{
FILE *fp;
int i, num = 3;
char passwd[PSDLEN + 1];
char checkPsd[PSDLEN + 1];

if((fp = fopen("psd.dat", "rb")) == NULL)
{
puts("Open psd.dat error");
exit(1);
}
fread(passwd, sizeof(char), PSDLEN, fp);
fclose(fp);
passwd[PSDLEN] = '\0';

printf("Please input password to login");
while(num)
{
printf("you have %d chances to cry:\n", num);
inputPsd(checkPsd);
if(!strcmp(passwd, checkPsd))
{
break;
}
puts("\npassword error,Please input again");
num--;
}
if(!num)
{
puts("Press any key to exit...");
getch();
exit(0);
}
else
{
puts("\n--------\nWelcome!\n--------\n");
}
}

void main()
{
if(checkFirst())
{
firstUse();
}
else
login();

getch();
}

⑻ C語言寫一個兩位的隨機數程序

這是2樓的,方法非常正確。
兩位數:也就是10~99了
這里可以用生成隨機數取余的方法得到,
比如任何整數除以100取余,那得到的是0~99的數,
那怎麼得到10~99呢?
任何整數除以90取余,那得到的是0~89的數,再加上10,也就是得到10~99的數了
#include
<stdlib.h>
#include
<stdio.h>
#include
<time.h>
void
main(
void
)
{
int
i,k;
srand(
(unsigned)time(
NULL
)
);
for(
i
=
0;
i
<
10;i++
)
{
k=rand()%90+10;
//這就OK了
printf(
"
k=%d\n",
k
);
}
}

⑼ 用c語言編寫一個設置密碼的程序

#include "stdio.h"
int* set(void);
int* set(void)
{
int i;
static a[4];
printf("請輸入要設置的4位密碼 :");
for(i=0;i<4;i++)
{
scanf("%d",&a[i]);
}
return a;
}

int main()
{
int i,*a,b[4];
a=set();
printf("請輸入4位密碼 :");
for(i=0;i<4;i++)
{
scanf("%d",&b[i]);
}
i=0;
while(i<4)
{
if(a[i]==b[i])
{
printf("%d",a[i]);
i++;
}
else
{
break;
}
}
if(i==4)
{
printf("密碼正確\n");
}
else
{
printf("密碼錯誤\n");
}
return 0;

}

⑽ c語言程序設計 密碼設置程序怎麼編寫

#include <stdio.h>
#include <string.h>
#include <conio.h>

int main(int argc,char *argv[])
{
const char user[]="wangpin";/*用戶名自己可改動*/
const char password[]="wangpin@126";/*密碼自己可改動*/
if(argc == 1)
{
printf("Input error! Usage:filename username password\n");
getch();
exit(1);
}
else if(argc == 3)
{
if (strcmp(argv[1],user) != 0 || strcmp(argv[2],password) != 0)
{
printf("Input error: Invalid username or password\n");
getch();
exit(1);
}
}
printf("Authentication Pass..\n");
sound(500);/*最簡單的音樂聲*/
delay(50000);
nosound();
getch();
return 0;
}

先運行這個程序得到一個exe類型的可執行文件,然後可以復制到c盤根目錄下,用桌面左下的圖標進入:開始-程序-附件-命令提示符
然後鍵入 cd \
到c盤根目錄下輸入
exe文件名 wangpin wangpin@126
就是運行這個程序
------------------------------------------------------------------
------------------------------------------------------------------
下面是一個簡單的音樂程序,你可以把它加到上面代替sound()到nosound()那一部分發出<<東方紅>>音樂歌曲(小心!聲音可能很大)
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>

int main(void)
{
int i,j;
int fr[]={392,392,440,294,262,262,220,294,392,392,
440,532,440,392,262,262,220,294,392,294,
262,247,220,196,392,294,330,294,262,262,
220,294,330,294,262,294,262,247,220,196};
int tim[]={4,2,2,8,4,2,2,8,4,4,2,2,2,2,4,2,2,8,4,
4,4,2,2,4,4,4,2,2,4,2,2,2,2,2,2,2,2,2,2,12};
for(i=0;i<40;i++)
{
sound(fr[i]);
delay(tim[i]*100000000);
nosound();
}
system("pause");
return 0;
}