Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #define MESSAGE_MAX_LENGHT 100;
- int encrypt(int value,int key);
- int decrypt(int value,int key);
- void encryptMessage(char* input, int key);
- void decryptMessage(char* input, int key);
- int main(){
- int key;
- char input[MESSAGE_MAX_LENGHT];
- printf("Introdu mesajul: ");
- gets(input);
- printf("Indou cheia:");
- scanf("%d",&key);
- encryptMessage(input, key);
- printf("Mesajul criptat: %s\n", input);
- decryptMessage(input, key);
- printf("Mesajul decriptat: %s\n", input);
- }
- int encrypt(int value, int key){
- int result=(value+key)%26;
- return result;
- }
- int decrypt(int value, int key){
- int result=(value-key+26)%26;
- return result;
- }
- void encryptMessage(char * input, int key){
- char message[MESSAGE_MAX_LENGHT];
- strcpy(message,input);
- int index=0;
- while(message[index] != '\0'){
- if(message[index] != ' ')
- if(message[index] <= 'Z' && message[index] >='A')
- input[index]=encrypt(message[index] - 'A' ,key) + 'A';
- else input[index]=encrypt(message[index] - 'a', key) + 'a';
- index++;
- }
- }
- void decryptMessage(char * input, int key){
- char message[MESSAGE_MAX_LENGHT];
- strcpy(message,input);
- int index=0;
- while(message[index] != '\0'){
- if(message[index] != ' ')
- if(message[index] <= 'Z')
- input[index] = decrypt(message[index] - 'A', key)+'A';
- else input[index] =decrypt(message[index] - 'a', key)+'a';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement