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

c語言密碼箱程序

發布時間: 2022-10-03 13:01:25

Ⅰ 求c語言或C++的電子密碼鎖程序

#include <stdio.h>
#include <conio.h> /*conio庫,調用無回顯getch()就是輸入後不顯示*/
#include <iostream>
using namespace std;
int main ()
{
int j=0;
int i;
char code[10];
char s;
for (i=3;i!=0;--i)
{
j=0;
printf("你還有%d次機會,請輸入密碼:\n",i);
cout<<"888888";
cout<<"\b\b\b\b\b\b";
while ((s=getch())!='\r')
{
code[j]=s;
if( s == '\b' ) //遇到退格鍵可以刪除前一個輸入
{
printf("\b8\b");
code[--j]=code[--j];
}
else
{
//putchar('*'); /*輸入的信息將以*號輸出*/
cout<<"F";
}
code[++j]='\0';
}
if (code[0]=='1'&&code[1]=='2'&&code[2]=='3'&&code[3]=='4'&&code[4]=='5'&&code[5]=='6'&&code[6]=='\0')
{
printf("\n密碼正確\n");
break;
}
//system("cls");
}
return 0;
}

不好意思,樓主,最近沒怎麼上網路,這個程序應該符合你的條件的,有什麼不懂的可以找我呢,單片機我不知道呢,不過這個程序是符合你的條件的,HI我吧

Ⅱ 如何用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語言程序設計 超市密碼存儲箱系統的設計與實現 要程序代碼,謝謝!

#include<stdio.h>
#include<malloc.h>
#include<math.h>
#include<stdlib.h>
#include<time.h>
typedef struct node
{
int num;
int password;
struct node *next;
}Node,*Linklist;
shuchu(Linklist LK,Linklist LM) /*輸出所有箱子情況界面*/
{
Linklist p,q;
p=LK->next;
q=LM->next;
while(p) /*空箱*/
{
printf(" ******\n");
printf(" * *\n");
printf(" * *\n");
printf(" ******\n");
if(p->password) printf(" 紅色\n\n");
else printf(" 藍色\n\n");
p=p->next;
}
while(q) /*滿箱*/
{
printf(" ******\n");
printf(" * *\n");
printf(" * *\n");
printf(" ******\n");
if(q->password) printf(" 紅色\n\n\n");
else printf(" 藍色\n\n");
q=q->next;
}
}
cunbao(Linklist LK,Linklist LM) /*存包*/
{
Linklist p,q;
srand((unsigned)time(NULL));
q=LM->next;
p=LK->next;
if(!p) /*判斷箱子是否已空*/
{
printf("箱滿,請稍侯!\n\n");
return;
}
while(p->password=rand()%900000+100000) /*生成密碼*/
{
if(!q) break;
q=LM->next;
while((p->password!=q->password))
{
q=q->next;
if(!q) break;
}
if(!q) break;
}
q=LM; /*空箱滿想的鏈接*/
while(q->next)
{
q=q->next;
}
LK->next=p->next;
q->next=p;
p->next=NULL;
shuchu(LK,LM);
printf(" 申請成功!您的密碼是:");
printf("%d\n\n",p->password);
}
qubao(Linklist LK,Linklist LM) /*取包*/
{
Linklist p,q,t;
int n;
q=LM->next;
t=LM;
p=LK;
printf("請輸入您的密碼:\n");
scanf("%d",&n);
while(q&&(q->password!=n))
{
q=q->next;
t=t->next;
}
if(!q) /*判斷密碼是否正確*/
{
printf("您輸入的密碼錯誤!\n\n");
return;
}
q->password=0;
t->next=q->next;
q->next=LK->next;
LK->next=q;
shuchu(LK,LM);
}
void main()
{
Linklist LK,LM,p,q;
int i=0,n,j;
LK=(Linklist)malloc(sizeof(Node)); /*生成鏈表*/
p=LK;
while(i<10)
{
q=(Linklist)malloc(sizeof(Node));
q->num=0;
q->password=0;
printf(" ******\n");
printf(" * *\n");
printf(" * *\n");
printf(" ******\n");
if(q->password) printf(" 紅色\n\n\n");
else printf(" 藍色\n\n");
p->next=q;
p=p->next;
i++;
}
p->next=NULL;
LM=(Linklist)malloc(sizeof(Node));
LM->next=NULL;
do /*主界面*/
{
printf(" ★==尊敬的客戶,您好!==★ \n\n");
printf(" ==========================================================\n\n");
printf(" 1,存包 \n\n");
printf(" 2,取包 \n\n");
printf(" 0,退出 \n\n");
printf(" ==========================================================\n\n");
printf("請輸入序號執行您的操作:\n\n");
scanf("%d",&n);
switch(n)
{
case 1:cunbao(LK,LM); break;
case 2:qubao(LK,LM); break;
case 0:break;
}
}while(n);
}

Ⅳ 用C語言設計一個文件加密與解密程序

c語言文件加密和解密方法如下:

1、首先打開VC++6.0;


4、聲明頭文件

#include<stdio.h>

#include<stdlib.h>

#include<string.h>


首先寫個加密函數,演算法就是簡介里說的;

voidEncryptFile(FILE*sfp,FILE*dfp,charpwd)
{
charch;
if(sfp==0||dfp==0)
{
printf("ERROR! ");
return;
}
while((ch=fgetc(sfp))!=EOF)
{
if((ch>='a')&&(ch<='z'))
{
ch=(ch-'a'+1)%26+'a';
ch=ch^pwd;
}
if((ch>='A')&&(ch<='Z'))
{
ch=(ch-'A'+1)%26+'A';
ch=ch^pwd;
}
fputc(ch,dfp);
}
}

寫解密子函數:與加密的過程相反;

voidDecryptFile(FILE*sfp,FILE*dfp,charpwd)
{
charch;
while((ch=fgetc(sfp))!=EOF)
{
if((ch>='a')&&(ch<='z'))
{
ch=ch^pwd;
ch=(ch-'a'+25)%26+'a';
}
if((ch>='A')&&(ch<='Z'))
{
ch=ch^pwd;
ch=(ch-'A'+25)%26+'A';
}
fputc(ch,dfp);
}
}

輸出函數,輸出文件內容
voidOutputFile(FILE*fp)
{
charch;
while((ch=fgetc(fp))!=EOF)
putchar(ch);
}
主函數,主要調用這幾個函數
intmain()
{
/*用戶輸入的要加密的文件名*/
charsfilename[20];
/*用戶輸入加密後保存的文件名*/
chardfilename[20];
/*用來保存密碼字元*/
charpwd;
FILE*sfp,*dfp;

printf(": ");
/*得到要加密的文件名*/
gets(sfilename);
/*得到加密後你要的文件名*/
printf(": ");
gets(dfilename);
/*得到加密字元*/
printf("PleaseinputyourPassword: ");
//scanf("%c",&pwd);
pwd=getch();
/*屏幕以*來表示輸入的加密字元*/
printf("* ");
/*以只讀方式打開要加密的文件*/
if((sfp=fopen(sfilename,"r"))==0)
{
printf("Can'topenthefile:%s ",sfilename);
exit(0);
}
/*輸出要加密的文件*/
printf(": ");
OutputFile(sfp);
/*建立加密後的文件*/
if((dfp=fopen(dfilename,"w+"))==0)
{
printf("Can'topenorcreatethefile:%s ",dfilename);
//exit(0);
}
/*文件加密*/
fseek(sfp,0L,SEEK_SET);
EncryptFile(sfp,dfp,pwd);
printf(" Encryptedthefilesuccessfully! ");
/*輸出加密後的文件*/
printf(": ");
fseek(dfp,0L,SEEK_SET);
OutputFile(dfp);
fclose(sfp);
fclose(dfp);
getch();
return0;
}

Ⅳ C語言密碼驗證的程序

#include<stdio.h>
void main()
{ int i,s;
for ( i=0;i<3;i++ )
{ scanf("%d",&s);
if ( s==12345 ) { printf("Welcome!\n"); break; }
else if ( i==3 ) printf("Sorry!\n");
else printf("Error!\n");
}
}

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

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

Ⅶ c語言編寫的程序,在輸入密碼時,如何加密

加密和解密演算法是程序編制中的重要一環。試想,如果我們平時使用的騰訊QQ、支付寶支付密碼、今日頭條賬號密碼那麼輕易就被別人盜取的話,很多不可以預料的事情就會發生!

在現實生活中,我們遇到過太多QQ密碼被盜取的情況,有的朋友QQ被盜之後,騙子利用朋友間信任騙取錢財的事情屢見不鮮。支付寶也曾出現過支付寶賬戶被惡意盜取的事件,對用戶利益造成了嚴重損害!這些在技術上都指向了同一相關問題:軟體加密演算法的強壯程度。今天,小編利用C語言來簡單實現一種加密方法。下面是源代碼。

需要說明:程序利用了ascii碼值的按照一定規律變換實現加密,對於解密過程,則是加密的逆過程。下面是程序的運行結果。

4190閱讀
搜索
編程免費課程300節
初學編程100個代碼
java自學一般要學多久
5秒破解excel密碼
python必背100源代碼
40歲零基礎學編程

Ⅷ 求51單片機C語言編的密碼鎖程序

#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define BIN(a,b,c,d,e,f,g,h) ((a<<7)+(b<<6)+(c<<5)+(d<<4)+(e<<3)+(f<<2)+(g<<1)+(h<<0))
//下面的code表示數組存放在ROM中,因為這個數組的值不需要改寫
uchar code KeyCode[16]={15,14,12,8,30,28,24,16,60,56,48,32,120,112,96,64};//值為m*(n+1)的乘積,用於Key()
uchar dis[6];
msdelay(uint x)//延時子函數
{uchar j;
while(x--)
{for(j=0;j<125;j++){;}
}
}
//鍵盤子程序一,鍵盤值與數組值對比得到
uchar Key(void)
{uchar temp,m,n,i,j,matrix,k;
P1=0xF0; /*行線電平為高,列線為低*/
temp=P1&0xf0;
if (temp==0xf0) return(16); /*行仍為高,無按健,退出*/
else msdelay(10);
for(i=1;i<16;i=i*2)
{m=i;
for(j=1;j<16;j=j*2)
{n=(~j)&0x0f;
P1=(m<<4)|n; /*m為P1的行值由i循環得到,n為列值,由j循環並取反得到*/
temp=P1&0xf0;
if (!temp)
{do{temp=P1&0xf0;}while(!temp);
matrix=m*(n+1);/*為避免乘積重復,n+1*/
for(k=0;k<16;k++){if (matrix==KeyCode[k]) return(k);} //KeyCode:見前
return(16);
} //if loop
}//j loop
}//i loop
}//Key end
//用Switch...case語句得到鍵盤值*/
uchar Key1(void)
{uchar temp,m,n,i,j,matrix;
P1=0xF0; /*行線電平為高,列線為低*/
temp=P1&0xf0;
if (temp==0xf0) return(16); /*行仍為高,無按健,退出*/
else msdelay(10);
for(i=1;i<16;i=i*2)
{m=i;
for(j=1;j<16;j=j*2)
{n=(~j)&0x0f;
P1=(m<<4)|n;/*m為P1的行值由i循環得到,n為列值,由j循環並取反得到*/
temp=P1&0xf0;
if (!temp)
{do{temp=P1&0xf0;}while(!temp);
matrix=m*(n+1);
switch(matrix) //此方法的基本思路:
{case 15:return(1); break; //由循環得到的m,n值賦於P1埠實現逐個鍵掃描
case 14:return(2); break; //同時由m,n+1的值相乘得到對應鍵點de的積
case 12:return(3); break; //m*(n+1)值掃描鍵點對應而得出鍵值
case 8:return(4); break; //
case 30:return(5); break; //
case 28:return(6); break; //
case 24:return(7); break; //
case 16:return(8); break;
case 60:return(9); break;
case 56:return(0); break;
case 48:return(10); break;
case 32:return(11); break;
case 120:return(12); break;
case 112:return(13); break;
case 96:return(14); break;
case 64:return(15); break;
default:return(16);
} //switch end
} //if loop
}//j loop
}//i loop
}//Key end
//依次掃描16個按鍵
uchar Key2(void)
{uchar temp;
P1=0xF0; /*使P1=1111 0000,行線電平為高,列線為低*/
temp=P1&0xf0;
if (temp==0xf0) return(16); /*讀P1=1111 xxxx,表示行仍為高,無按健,退出(x表示不關心)?/
else msdelay(10);
P1=0x1e; /*P1=0001 1110,行一為高,列一為低,掃描第一個按鍵*/
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(1);}
P1=0x1d; /*P1=0001 1101,行一為高,列二為低,掃描第二個按鍵,下面掃描其餘按鍵*/
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(2);}
P1=0x1b;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(3);}
P1=0x17;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(4);}
P1=0x2e;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(5);}
P1=0x2d;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(6);}
P1=0x2b;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(7);}
P1=0x27;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(8);}
P1=0x4e;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(9);}
P1=0x4d;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(0);}
P1=0x4b;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(10);}
P1=0x47;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(11);}
P1=0x8e;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(12);}
P1=0x8d;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(13);}
P1=0x8b;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(14);}
P1=0x87;
temp=P1&0xf0;
if (!temp) {do{temp=P1&0xf0;}while(!temp);
return(15);}

return(16); //掃描all按鍵都未按下,則輸出16
}//Key2 end.
////////時鍾中斷顯示子程序
void T0_int() interrupt 1
{static uchar i;
if (i==6){i=0;}
P0=5-i;
P0=P0|(dis[i]<<4);
i++;
TL0=0;
TH0=252;}

void distri(uint disnum)
{uint temp;
dis[0]=0;
dis[1]=disnum/10000;
temp=disnum%10000;
dis[2]=temp/1000;
temp=temp%1000;
dis[3]=temp/100;
temp=temp%100;
dis[4]=temp/10;
dis[5]=temp%10;
}
Main()
{uchar KeyVal,i=0;
TMOD=0x01;
IE=0x82;
TH0=252;
TL0=0;
TR0=1;
distri(0);
do{
KeyVal=Key();
if (KeyVal!=16) dis[1]=KeyVal; //注意:當有按鍵時才賦於顯示位dis[1],否則出錯,請分析!
}while(1);
}

Ⅸ 用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<5;i++)
for(int j=0;j<5;j++)
{
if(count<strlen(MiYao))
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<5;i++)
{ for(int j=0;j<5;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<5;i++)
for(int j=0;j<5;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<len;i+=2)
{
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;
}