Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- #include<ctype.h>
- #define STRING 255
- #ifndef Crypto_h
- #define Crypto_h
- void input(char *);
- void encrypt(char []);
- void decrypt(char []);
- #endif
- #include "Crypto.h"
- void main()
- {
- char message[STRING];
- int shift, choice;
- input(message);
- printf("\n\nChoose an operation:\n\n\t1.\tEncryption\n\t2.\tDecryption\n\n\tAny other\tExit.\n");
- scanf_s("%d", &choice);
- if (choice==1)
- {
- encrypt(message);
- _getch();
- }
- else if (choice == 2)
- {
- decrypt(message);
- _getch();
- }
- }\\#include "Crypto.h"
- void input(char *message)
- {
- printf_s("Please enter a message: \n");
- fgets(message, 250, stdin);
- for (int i=0;i<strlen(message);i++)
- {
- message[i]=toupper(message[i]);
- }
- }
- void encrypt(char message[])
- {
- int shift;
- printf("\nPlease enter shift key\n");
- scanf_s("%d", &shift);
- for (int i=0;i<strlen(message)-1;i++)
- {
- if (message[i] != ' ')
- {
- message[i] = ((message[i] -'A' + shift) %26)+'A';
- }
- }
- puts(message);
- }
- void decrypt(char message[])
- {
- int shift;
- printf("\nPlease enter shift key\n");
- scanf_s("%d", &shift);
- for (int i = 0; i<strlen(message) - 1; i++)
- if (message[i] != ' ')
- {
- if ((message[i] - 'A' - shift)<0)
- message[i] = (message[i] - 'A' - shift)+26+'A';
- else
- message[i] = ((message[i] - 'A' - shift) % 26) + 'A';
- }
- puts(message);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement