Caesar Classification Algorithm C Language Realization

xiaoxiao2021-03-06  38

#include

#include

Char Encrypt (CHAR CH, INT N) / * Encryption function, shift characters to right cycle n * / {while (chiple) {return ('a' (CH- 'A' n)% 26);} while (chile (CH> = 'a' && ch <= 'z') {RETURN ('A' (CH-'A ' N)% 26);} Return CH; }

Void menu () / * menu, 1. Encryption, 2. decryption, 3. Violent crack, password can only be digital * / {clrs (); printf ("/ n ============ ============================================================================================================================================================================================================= ================== "); Printf (" / n1.encrypt the file "); Printf (" / n2.decrypt the file "); Printf (" / N3. Force Decrypt File "); Printf (" / n4.quit / n "); printf (" ========================================================= ============================================================================================================================================================================================================= / N "); Printf (" Please select a item: "); return;}

Void logo () / * Display copyright information * / {printf ("/ nzhensoft encryption [Version: 1.0.0]"); Printf ("/ ncopyright (c) 2004 zhensoft corp./n" );printf ("nhttp : //www.zhensoft.com/n "); Return;}

MAIN () {Int i, n; char CH0, CH1; File * in, * out; char infile [20], outfile [20];

Textbackground (Black); TextColor (Lightgreen); ClrsCr (); logo (); Sleep (3); / * Wait 3 seconds * /

Menu (); ch0 = getCH ();

While (CH0! = '4') {IF (CH0 == '1') {clrs CR (); Printf ("/ NPLEASE INPUT The Infile:"); Scanf ("% s", infile); / * Input needs Encrypted file name * /

IF ((IN = fopen (Infile, "R")) == null) {Printf ("can not open the infile! / n"); Printf ("press any key to exit! / n"); getCh () EXIT (0);

Printf ("Please Input The Key:"); Scanf ("% D", & n); / * Enter the encryption password * /

Printf ("" please input the outfile: "; scanf ("% s ", outfile); / * Enter the file name of the encrypted file * /

IF (out = fopen (outfile, "w")) == null) {Printf ("can not open the outfile! / n"); Printf ("Press any key to exit! / n"); fclose (in ); GetCh (); exit (0);

While (! feof) / * encryption * / {FPUTC (Encrypt (Fgetc (in), N), OUT;

Printf ("/ Nencrypt is over! / n"); fclose (in); fclose (out); SLEEP (1);}

IF (CH0 == '2') {clrs CR (); Printf ("/ NPLEase Input the Infile:"); Scanf ("% s", infile); / * Enter file name to decrypt * /

IF ((IN = fopen (Infile, "R")) == null) {Printf ("can not open the infile! / n"); Printf ("press any key to exit! / n"); getCh () EXIT (0);

Printf ("" please input the key: "); scanf ("% d ", & n); / * Enter the decryption password (can be encrypted) * /

N = 26-N;

Printf ("please input the outfile:"); scanf ("% s", outfile); / * Enter the file name of the file after decryption * /

IF (out = fopen (outfile, "w")) == null) {Printf ("can not open the outfile! / n"); Printf ("Press any key to exit! / n"); fclose (in ); GetCh (); exit (0);

While (! Feof (in) {FPUTC (Encrypt (FGETC (IN), N), OUT;} Printf ("/ NDecrypt IS over! / n"); Fclose (in); fclose (out); SLEEP 1);} if (CH0 == '3') {ClRSCR (); Printf ("/ NPLEASE INPUT The Infile:"); Scanf ("% s", infile); / * Enter file name to decrypt * /

IF ((IN = fopen (Infile, "R")) == null) {Printf ("can not open the infile! / n"); Printf ("press any key to exit! / n"); getCh () EXIT (0);

Printf ("please input the outfile:"); scanf ("% s", outfile); / * Enter the file name of the file after decryption * /

IF (out = fopen (outfile, "w")) == null) {Printf ("can not open the outfile! / n"); Printf ("Press any key to exit! / n"); fclose (in ); GetCh (); exit (0);

For (i = 1; i <= 25; i ) / * violent cracking process, after the information is checked, you can press 'Q' or 'q' to exit * / {REWIND (IN); REWIND (OUT); CLRSCR ); Printf ("============================================= ============================================ / n "); Printf (" the outfile is: / n ") PRINTF ("============================================================================================================================================================================== =========================================== / n "); While (! feof (in)) {ch1 = encrypt (FGETC (IN), 26-I); PUTCH (CH1); FPUTC (CH1, OUT);} Printf ("/ n ===================== ============================================================================================================================================================================================================= ========= / n "); Printf (" THE CURRENT Key IS:% D / N ", I); / * Displays the password used in the current crack * / printf (" Press 'q' to quit and other Key to Continue ... / n "); Printf (" =======

============================================================================================================================================================================================================= ======================= / n "); CH1 = getCH (); if (CH1 == 'q' || CH1 == 'q') / * With 'Q' or 'q', exit * / {clrs (); logo (); Printf ("/ ngood bye! / N"); fclose (in); fclose (out); SLEEP (3); Exit (0);}} Printf ("/ NFORCE DECRYPT IS over! / n"); fclose (in); fclose (out); Sleep (1);} menu (); ch0 = getCH ();} CLRSCR ); logo (); printf ("/ ngood bye! / n"); SLEEP (3);

转载请注明原文地址:https://www.9cbs.com/read-66283.html

New Post(0)