Question

In: Computer Science

write a C program which performs encryption and decryption of a message

write a C program which performs encryption and decryption of a message

Solutions

Expert Solution

// C Program for encyption and decryption of message
#include <stdio.h> // Header File

int main()
{
int i, x;
char str[100];

printf("\nPlease enter a string:\t");
gets(str);

printf("\nPlease choose following options:\n");
printf("1 = Encrypt the string.\n");
printf("2 = Decrypt the string.\n");
scanf("%d", &x);

//using switch case
switch(x)
{
case 1:
for(i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] + 10; //the key for encryption is 10 that is added to ASCII value

printf("\nEncrypted string: %s\n", str);
break;

case 2:
for(i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] - 10; //the key for encryption is 10 that is subtracted to ASCII value

printf("\nDecrypted string: %s\n", str);
break;

default:
printf("\nError\n");
}
return 0;
}

Output Snapshot:


Related Solutions

Your task is to write a C program which performs encryption and decryption of a message...
Your task is to write a C program which performs encryption and decryption of a message using the substitution cipher algorithm. Write a C program which performs encryption and decryption using the substitution cipher algorithm. Your program must be fully automated (ie: it does not take any interactive user input) and either encrypt or decrypt depending on the files which exist in the program’s directory. If message.txt exists your program should read that file, encrypt the contents, and write the...
My question below Write a complete program that performs encryption/decryption of a text file. Encryption means...
My question below Write a complete program that performs encryption/decryption of a text file. Encryption means you need to scramble the words of a file to become secure. Decryption means you need to apply some rules to an encrypted file in order to find the original file with its original content. An example of encryption is to replace each letter in a file with its consecutive letter in the alphabet. Therefore, ‘a’ is replaced by ‘b’, ‘b’ is replaced by...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The program should be able to handle different keys by deciding the key at run time. Thank you :)
Write a program in c++ that can perform encryption/decryption. In the following let the alphabet A...
Write a program in c++ that can perform encryption/decryption. In the following let the alphabet A be A={A, a, B, b, . . ., “ ”, “.”,“’ ”}. The encoding is A→0, a→1, B→2, b→4, . . ., Z→50, z→51, “ ”→52, “.”→53 and “’”→54.
Write a program in java that can perform encryption/decryption. In the following let the alphabet A...
Write a program in java that can perform encryption/decryption. In the following let the alphabet A be A={A, a, B, b, . . ., “ ”, “.”,“’ ”}. The encoding is A→0, a→1, B→2, b→4, . . ., Z→50, z→51, “ ”→52, “.”→53 and “’”→54.
Alice is sending message “HIDE” to Bob. Perform encryption and decryption using RSA algorithm, with the...
Alice is sending message “HIDE” to Bob. Perform encryption and decryption using RSA algorithm, with the following information: parameters p=11,q=5, e=7 Present all the information that you will need to encrypt and decrypt only the first letter from text
In the caeser cipher encryption and decryption program below, what do the two lines if(ch >...
In the caeser cipher encryption and decryption program below, what do the two lines if(ch > 'z'){ ch = ch - 'z' + 'a' - 1; } if(ch < 'a'){ ch = ch + 'z' - 'a' + 1; } mean??? I understand that it has something to do with ASCII characters and makes sure that if the encryption/decryption character is more than "z", then it would loop back to "a" instead of outputting a charcter like "{" . I...
With C code Write a switch statement (not a complete program) which prints an appropriate message...
With C code Write a switch statement (not a complete program) which prints an appropriate message for a letter code entered. Use the following messages: If L is entered, output the message "Lakers" If C is entered, output the message "Clippers" If W is entered, output the message "Warriors" If any other character is entered, output the message "invalid code" Make sure to handle the case where the user enters in a small letter. That is, a capital or small...
In C: Write a complete program that performs the following task: Ask the user for the...
In C: Write a complete program that performs the following task: Ask the user for the number of sequences to display. For each sequence, Ask the user for a starting value Print out the value and double it (multiply by 2). Continue printing and doubling (all on the same line, separated by one space each) as long as the current number is less than 1000, or until 8 numbers have been printed on the line. You may assume that the...
We like to apply text encryption and decryption as follows. In text encryption, for each letter...
We like to apply text encryption and decryption as follows. In text encryption, for each letter and numeric character in the plaintext (i.e., a-z, A-Z and 0-9), it is “shifted” a certain number of places down the alphabet or numbers. For example, assuming a shifted key offset of 3 is used, ‘A’ would be substituted by ‘D’, ‘B’ would become ‘E’, and so on. Similarly, ‘0’ would become ‘3’ and so on. Note that wrap-around will be applied at the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT