Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <string.h>
- #include <windows.h>
- const char upper_alph[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
- const char lower_alph[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
- void wait()
- {
- for (int i= 0; i<=100; i++)
- {
- printf("\n\n\n\n\n\n\n\n\n");
- printf("\t ============================================================ \n");
- printf("\t || ____________________________________________________ || \n");
- printf("\t || | | || \n");
- printf("\t Please Wait %d % \n", i);
- printf("\t || |____________________________________________________| || \n");
- printf("\t || || \n");
- printf("\t ============================================================ \n");
- system ("cls");
- }Sleep(200);
- }
- void thank();
- {
- int i,j,k,m;
- char kata[10][10]={{'T','H','A','N','K'},{'Y','O','U'},{'A','N','D'}};
- printf("\t\t\t");
- for(i=0; kata[i][0]!='\0';i++)
- {}
- for(j=0;j<=i;j++)
- {
- for(k=0;kata[j][k]!='\0';k++)
- {}
- for(m=0;m<=k-1;m++)
- {
- printf("%c",kata[j][m]);Sleep(100);
- }
- printf(" ");Sleep(100);
- }
- }
- void emoticon()
- {
- int i,j,k,m;
- char kata[10][10]={{'H','O','P','E','F','U','L','L','Y'},{'U','S','E','F','U','L'},{'^','_','^'}};
- for(i=0; kata[i][0]!='\0';i++)
- {}
- for(j=0;j<=i;j++)
- {
- for(k=0;kata[j][k]!='\0';k++)
- {}
- for(m=0;m<=k-1;m++)
- {
- printf("%c",kata[j][m]);Sleep(100);
- }
- printf(" ");Sleep(100);
- }
- printf("\n");
- }
- char num(char c)
- {
- if(isupper(c))
- {
- for(int i = 0; i < 26; i++)
- if(upper_alph[i] == c)
- return i;
- }
- else
- {
- for(int i = 0; i < 26; i++)
- if(lower_alph[i] == c)
- return i;
- }
- return 0;
- }
- void encrypt(char *message, int shift)
- {
- int i = 0;
- while(message[i] != NULL)
- {
- if(isalpha(message[i]))
- {
- if(isupper(message[i]))
- {
- printf("%c", upper_alph[(num(message[i])+shift)%26]);
- }
- else
- {
- printf("%c", lower_alph[(num(message[i])+shift)%26]);
- }
- }
- else
- {
- printf("%c", message[i]);
- }
- i++;
- }
- }
- void decrypt(char *message, int shift)
- {
- int i = 0;
- int iserror;
- int error;
- while(message[i] != NULL)
- {
- if(isalpha(message[i]))
- {
- if(isupper(message[i]))
- {
- iserror=(num(message[i])-shift)%26+1;
- //printf("%i",iserror);
- if(iserror>0)
- printf("%c", upper_alph[(num(message[i])-shift)%26]);
- else
- {
- error=((num(message[i])-shift)%26)+26;
- //printf("%i",error);
- printf("%c", upper_alph[error]);
- }
- }
- else
- {
- iserror=(num(message[i])-shift)%26+1;
- //printf("%i",iserror);
- if(iserror>0)
- printf("%c", lower_alph[(num(message[i])-shift)%26]);
- else
- {
- error=((num(message[i])-shift)%26)+26;
- //printf("%i",error);
- printf("%c", lower_alph[error]);
- }
- }
- }
- else
- {
- printf("%c", message[i]);
- }
- i++;
- }
- }
- #define OK 0
- #define NO_INPUT 1
- #define TOO_LONG 2
- static int getLine (char *prmpt, char *buff, size_t sz)
- {
- int ch, extra;
- // Get line with buffer overrun protection.
- if (prmpt != NULL) {
- printf ("%s", prmpt);
- fflush (stdout);
- }
- if (fgets (buff, sz, stdin) == NULL)
- return NO_INPUT;
- // If it was too long, there'll be no newline. In that case, we flush
- // to end of line so that excess doesn't affect the next call.
- if (buff[strlen(buff)-1] != '\n') {
- extra = 0;
- while (((ch = getchar()) != '\n') && (ch != EOF))
- extra = 1;
- return (extra == 1) ? TOO_LONG : OK;
- }
- // Otherwise remove newline and give string back to caller.
- buff[strlen(buff)-1] = '\0';
- return OK;
- }
- int main()
- {
- system("color 02");
- printf("\n\n #####\n");
- printf("# # ##### # # ##### ##### #### #### ##### ## ##### # #\n");
- printf("# # # # # # # # # # # # # # # # # # # #\n");
- printf("# # # # # # # # # # # # # # # # ######\n");
- printf("# ##### # ##### # # # # ### ##### ###### ##### # #\n");
- printf("# # # # # # # # # # # # # # # # # #\n");
- printf(" ##### # # # # # #### #### # # # # # # #\n");
- printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
- printf("+ Program Created by Vaisakh and Abdul +\n");
- printf("+ +\n");
- printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
- printf("+One of the many encryption programs that use Caesar Chiper Tecnique for +\n");
- printf("+encryption and decryption. This program using C++ language. +\n");
- printf("+ +\n");
- printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n\n");
- printf("\n\n\n\n\nPress Any Key to Continue");
- getche();
- wait();
- main:
- system("cls");
- int rc, shift,i,j, again;
- int opt;
- char mes[1024],a;
- int sh = 0;
- printf("+==============================================================================+");
- printf("| CRYPTOGRAPH [Caesar Chiper | C++] |");
- printf("+------------------------------------------------------------------------------+");
- printf("| Done by Vaisah K Nair and Abdul Razzak V |");
- printf("| |");
- printf("+==============================================================================+\n\n");
- rc = getLine ("Enter message to be encrypted or decrypted: ", mes, sizeof(mes));
- if (rc == NO_INPUT)
- {
- // Extra NL since my system doesn't output that on EOF.
- printf ("\nNo input\n");
- return 1;
- }
- if (rc == TOO_LONG) {
- printf ("Input too long [%s]\n", mes);
- return 1;
- }
- j=strlen(mes);
- back_1:
- printf("\n\nPlease, Select One Option\n");
- printf("1. Encryption\n");
- printf("2. Decryption\n");
- printf("Your Option : ");
- scanf("%i",&opt);
- printf("\n\nHow Much Shift (example : 1) : ");
- scanf("%i",&shift);
- switch(opt){
- case 1 :
- encryp:
- system("cls");
- printf("+==============================================================================+");
- printf("| CRYPTOGRAPH [Caesar Chiper | C++] | ENCRYPTION |");
- printf("+------------------------------------------------------------------------------+");
- printf("| Done by Vaisah K Nair and Abdul Razzak V |");
- printf("+==============================================================================+\n\n");
- printf("RESULT : \n\n");
- encrypt(mes, shift);
- printf("\n\n\nYOUR INPUT :\n\n");
- for(i=0;i<j;i++)
- {
- printf("%c", mes[i]);
- }
- break;
- case 2:
- decryp:
- system("cls");
- printf("+==============================================================================+");
- printf("| CRYPTOGRAPH [Caesar Chiper | C++] | DECRYPTION |");
- printf("+------------------------------------------------------------------------------+");
- printf("| Done by Vaisah K Nair and Abdul Razzak V |");
- printf("+==============================================================================+\n\n");
- printf("RESULT : \n\n");
- decrypt(mes, shift);
- printf("\n\n\nYOUR INPUT :\n\n");
- for(i=0;i<j;i++)
- {
- printf("%c", mes[i]);
- }
- break;
- default :
- printf("Your Selection is Wrong.\n Please, Select Again\n");
- getche();
- goto back_1;
- break;
- }
- printf("\n\n+==============================================================================+");
- printf("\nPlease, Select One Option\n");
- printf("1. Main Menu\n");
- printf("2. ");
- if(opt==1)
- {
- printf("Decryption (");
- opt=2;
- }
- else
- {
- printf("Encryption (");
- opt=1;
- }
- if(j>10)
- {
- for(i=0;i<=10;i++)
- {
- printf("%c", mes[i]);
- }
- printf("...");
- }
- else
- {
- for(i=0;i<=j;i++)
- {
- printf("%c", mes[i]);
- }
- }
- printf(")\n3. Exit\n");
- printf("Your Opt : ");
- scanf("%i",&again);
- scanf("%c",&a);
- if(again==1)
- {
- goto main;
- }
- else if(again==2)
- {
- if(opt==1)
- goto encryp;
- else
- goto decryp;
- }
- else
- {
- thank();
- emoticon();
- }
- fflush(stdin);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement