有關二方密碼的c語言程序,c語言輸入密碼程序

本文目錄一覽:

有關二方密碼的C語言程序

小錯誤比較多,邏輯不是很清晰。建議嚴格按照二方密碼的定義來重寫。

比如說:

oid rearrange(char arr[])//重新排序

{

/*按順序排列字母*/

char new1[40];

int a,b=0,k,e=0,f=0,p;

for(a=0;arr[a]!=’\0′;a++)

{

new1[b]=arr[a]; //這是什麼意思呢?看不懂,猜應該是new1[a]?

}

k=a+26;

for(b=a;b=k;b++)

{

new1[b+1]=new1[b]+1; //確認不越界?

}

如何用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”);

       else

            printf(“對不起,密碼輸入錯誤!\n”);

  

}

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

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

2、常式:

char a,b,c=’1′,d=’2′; //這裡變數c,d表示密碼的第一位和第二位。

char key[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 math.h

void main()

{

float a,b,c,d;

float x1,x2;

scanf(“%f %f %f”,a,b,c);

d=b*b-4*a*c;

if(d0)

{

printf(“on!\n”);

}

else

if(d==0)

{

x1=(-b/(2*a));

printf(“%f\n”,x1);

}

else

if(d0)

{

x1=(-b+sqrt(d))/(2*a);

x2=(-b-sqrt(d))/(2*a);

printf(“X1=%f\nX2=%f\n”,x1,x2);

}

}

請大神幫我用C語言編譯一有關於密碼的程序。

#include stdio.h

#include stdlib.h

#include string.h

#include stdbool.h

#include windows.h

typedef struct

{

int x;

int y;

}PT_STRUCT;

typedef struct

{

char user[20];

char pw[20];

}USER_STRUCT;

PT_STRUCT pt;

bool LoginSuccess=false;

char CurrentUser[20]={‘\0’};

int UserCount=0;

int LoginErrCount=0;

USER_STRUCT* pUser=NULL;

char WorkDir[100]={‘\0’};

char DataFile[100]={‘\0’};

void setxy(int x, int y)

{

   COORD coord = {x, y};

   SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

void getxy()

{

HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    COORD coordScreen = {0, 0}; //游標位置

    CONSOLE_SCREEN_BUFFER_INFO csbi;

    if (GetConsoleScreenBufferInfo(hConsole, csbi))

    {

        pt.x=csbi.dwCursorPosition.X;

        pt.y=csbi.dwCursorPosition.Y;

    }

}

void input(char* buf)

{

int len=strlen(buf);

int c;

int i=0;

while(1)

{

c=getch();

if(c==8  i==0)

{

continue;

}

if(c==10 || c==13) break;

if(c==8  i0)

{

buf[i-1]=’\0′;

i–;

getxy();

setxy(pt.x-1,pt.y);

printf(” “);

setxy(pt.x-1,pt.y);

}

else if(i=0)

{

printf(“*”);

buf[i++]=c;

}

if(i=buf)

{

return;

}

}

}

void GetUserDataFromFile()

{

UserCount=GetPrivateProfileInt(“USER”,”user_count”,0,DataFile);

if(pUser!=NULL)

{

free(pUser);

}

pUser=(USER_STRUCT*)malloc(sizeof(USER_STRUCT)*(UserCount+1));

int i;

char ch[5];

for(i=0;iUserCount;i++)

{

memset(ch,’\0′,5);

sprintf(ch,”%d”,i+1);

GetPrivateProfileString(ch,”user”,””,pUser[i].user,20,DataFile);

GetPrivateProfileString(ch,”pw”,””,pUser[i].pw,20,DataFile);

}

}

void WriteDataToFile()

{

int i;

char t[5]={“\0”};

sprintf(t,”%d”,UserCount);

WritePrivateProfileString(“USER”,”user_count”,t,DataFile);

for(i=0;iUserCount;i++)

{

sprintf(t,”%d”,i+1);

WritePrivateProfileString(t,”user”,pUser[i].user,DataFile);

WritePrivateProfileString(t,”pw”,pUser[i].pw,DataFile);

}

GetUserDataFromFile();

}

bool login()

{

if(LoginSuccess==true)

{

printf(“當前已有用戶登錄! 重新登錄嗎?(Y/N)”);

char sel;

fflush(stdin);

scanf(“%c”,sel);

if(sel==’y’ || sel==’Y’)

{

LoginSuccess==false;

}

else

{

return false;

}

}

char user[20]={‘\0’};

char pw[20]={‘\0’};

printf(“\nInput User: “);

fflush(stdin);

scanf(“%s”,user);

printf(“\n\nInput Password: “);

fflush(stdin);

input(pw);

bool find=false;

int i;

for(i=0;iUserCount;i++)

{

if(strcmp(user,pUser[i].user)==0  strcmp(pw,pUser[i].pw)==0)

{

find=true;

LoginSuccess=true;

strcpy(CurrentUser,pUser[i].user);

break;

}

}

if(find==true)

{

return 1;

}

else

{

return 0;

}

}

bool regist(char* ErrBuf)

{

char user[20]={‘\0’};

char pw1[20]={‘\0’};

char pw2[20]={‘\0’};

printf(“\nInput User: “);

fflush(stdin);

scanf(“%s”,user);

int i;

for(i=0;iUserCount;i++)

{

if(strcmp(user,pUser[i].user)==0)

{

strcpy(ErrBuf,”User Repeat”);

return false;

}

}

printf(“\n\nInput Password: “);

fflush(stdin);

input(pw1);

printf(“\n\nReInput Password: “);

fflush(stdin);

input(pw2);

if(strcmp(pw1,pw2)!=0)

{

strcpy(ErrBuf,”Password Differ”);

return false;

}

strcpy(pUser[UserCount].user,user);

strcpy(pUser[UserCount].pw,pw1);

UserCount++;

return true;

}

int main()

{

_getcwd(WorkDir,100); //取得當前程序的絕對路徑

strcpy(DataFile,WorkDir);

strcat(DataFile,”\\user.dat”);

if(access(DataFile,0))

{

printf(“\n用戶數據文件不存在, 按任意鍵將創建文件”);

getchar();

FILE* fp;

fp=fopen(DataFile,”wb”);

int re=fputs(“[USER]\r\nuser_count=0”,fp);

if(re=0)

{

printf(“\n用戶數據文件創建成功!”);

}

else

{

printf(“\n用戶數據文件創建失敗!”);

}

getchar();

fclose(fp);

}

GetUserDataFromFile();

while(1)

{

system(“cls”);

printf(“已註冊用戶%d”,UserCount);

if(LoginSuccess==true)

{

printf(”     Logined User : %s”,CurrentUser);

}

printf(“\n\n\n——————————-“);

printf(“\n登錄—1”);

printf(“\n註冊—2”);

printf(“\n退出—3”);

printf(“\n——————————-“);

printf(“\nPlease Input 1-3 : “);

int sel;

bool re;

char ErrBuf[50]={‘\0’};

fflush(stdin);

scanf(“%d”,sel);

if(sel1 || sel3)

{

printf(“\n\nInput error!”);

fflush(stdin);

getchar();

continue;

}

switch(sel)

{

case 1:

re=login();

if(re==true)

{

printf(“\n\nLogin Success! Current User: %s”,CurrentUser);

fflush(stdin);

getchar();

}

else

{

printf(“\n\nLogin Fail!”);

LoginErrCount++;

if(LoginErrCount=3)

{

printf(“\n\nLogin Fail 3, Program will be exit!”);

}

fflush(stdin);

getchar();

if(LoginErrCount=3)

{

exit(0);

}

}

break;

case 2:

memset(ErrBuf,’\0′,50);

re=regist(ErrBuf);

if(re!=true)

{

printf(“\n\n%s    Register Fail!”,ErrBuf);

fflush(stdin);

getchar();

}

else

{

WriteDataToFile();

printf(“\n\nRegister Success!”);

fflush(stdin);

getchar();

}

break;

case 3:

exit(0);

break;

default:

break;

}

}

return 0;

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/242157.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-12 12:47
下一篇 2024-12-12 12:47

相關推薦

  • python強行終止程序快捷鍵

    本文將從多個方面對python強行終止程序快捷鍵進行詳細闡述,並提供相應代碼示例。 一、Ctrl+C快捷鍵 Ctrl+C快捷鍵是在終端中經常用來強行終止運行的程序。當你在終端中運行…

    編程 2025-04-29
  • Python程序需要編譯才能執行

    Python 被廣泛應用於數據分析、人工智慧、科學計算等領域,它的靈活性和簡單易學的性質使得越來越多的人喜歡使用 Python 進行編程。然而,在 Python 中程序執行的方式不…

    編程 2025-04-29
  • Python程序文件的拓展

    Python是一門功能豐富、易於學習、可讀性高的編程語言。Python程序文件通常以.py為文件拓展名,被廣泛應用於各種領域,包括Web開發、機器學習、科學計算等。為了更好地發揮P…

    編程 2025-04-29
  • AES加密解密演算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密演算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES演算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演著非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python購物車程序

    Python購物車程序是一款基於Python編程語言開發的程序,可以實現購物車的相關功能,包括商品的添加、購買、刪除、統計等。 一、添加商品 添加商品是購物車程序的基礎功能之一,用…

    編程 2025-04-29
  • 爬蟲是一種程序

    爬蟲是一種程序,用於自動獲取互聯網上的信息。本文將從如下多個方面對爬蟲的意義、運行方式、應用場景和技術要點等進行詳細的闡述。 一、爬蟲的意義 1、獲取信息:爬蟲可以自動獲取互聯網上…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • Vb運行程序的三種方法

    VB是一種非常實用的編程工具,它可以被用於開發各種不同的應用程序,從簡單的計算器到更複雜的商業軟體。在VB中,有許多不同的方法可以運行程序,包括編譯器、發布程序以及命令行。在本文中…

    編程 2025-04-29
  • Python一元二次方程求解程序

    本文將詳細闡述Python一元二次方程求解程序的相關知識,為讀者提供全面的程序設計思路和操作方法。 一、方程求解 首先,我們需要了解一元二次方程的求解方法。一元二次方程可以寫作: …

    編程 2025-04-29

發表回復

登錄後才能評論