Question

Question: Please Provide Comments on each Line of code explaining what the C Function is doing throughout the code. // Function used for substitution encryption                     void SubEncrypt(cha...

Question: Please Provide Comments on each Line of code explaining what the C Function is doing throughout the code.

// Function used for substitution encryption  
                 
void SubEncrypt(char *message, char *encryptKey) {
int iteration = 0;
printf("Enter Aphabet Encryption Key: \n");
scanf("%s", encryptKey);

  
for (iteration = 0; iteration < strlen(message); iteration++)
{
char letter = message[iteration];
if (letter >= 'A' && letter <= 'Z')
{
  
letter = encryptKey[letter - 'A'];
}

message[iteration] = letter;
}
printf("CipherText message: %s\n", message);
}

//_________________________________________________________________________________________________________________________________________________
// Function used for substitution decryption

void SubDecrypt(char *message, char *encryptKey) {
int iteration;
int iteration_Num_Two = 0;
int letter;
printf("Enter Encryption Key: \n");
scanf("%s", encryptKey);
for (iteration = 0; message[iteration] != '0'; iteration++)
{
letter = message[iteration];
if (letter >= 'A' && letter <= 'Z')
{
letter = letter - 32;
}
if (letter >= 65 && letter <= 90) {
  
for (iteration_Num_Two = 0; iteration_Num_Two < 27; iteration_Num_Two++)
{
if (message[iteration] == encryptKey[iteration_Num_Two])
{
break;
}
}
message[iteration] = 'A' + iteration_Num_Two;
  
}
printf("%s\n", message);

}
;
printf("CipherText message: %s\n", message);
printf("%s\n", encryptKey);
}

// End Function Void SubDecrypt
//_________________________________________________________________________________________________________________________________________________

// Function used for rotation decryption without using a key

void RotDecrypt_Without_Key(char *message, int key) {
printf("Enter ciphertext to decrypt: \n");
  
int iteration;
char letter;
int count = 1;
  
for (count = 1; count <26; count++) {
  
for(iteration = 0; message[iteration] != '\0'; ++iteration){
letter = message[iteration];
key = 1;
  
if(letter >= 'A' && letter <= 'Z'){
letter = letter - key;
  
if(letter < 'A'){
letter = letter + 'Z' - 'A' + 1;
}
  
message[iteration] = letter;
}
  
  
else if(letter >= 'a' && letter <= 'z'){
letter = letter - key;
  
if(letter < 'a'){
letter = letter + 'z' - 'a' + 1;
}
  
message[iteration] = letter;
}
  
key = key++;
}
  
printf("Plaintext message: %s\n", message);
  
}
  
}

// End Function Void RotDecrypt_Without_Key

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Function used for substitution encryption

void SubEncrypt(char *message, char *encryptKey)
{
int iteration = 0;
//display the message to input Alphabet Encryption key
printf("Enter Aphabet Encryption Key: \n");
//read the encryption key
scanf("%s", encryptKey);

//loop will continue from 0 to the end of message
for (iteration = 0; iteration < strlen(message); iteration++)
{
   //assign the character at message[iteration] to letter
char letter = message[iteration];
//check for uppercase character
if (letter >= 'A' && letter <= 'Z')
{
//update the value of letter by assigning the chracter at encryptKey[letter-'A']
letter = encryptKey[letter - 'A'];
}
//store the letter to message[iteration]
message[iteration] = letter;
}
//display the cipher text
printf("CipherText message: %s\n", message);
}

//_________________________________________________________________________________________________________________________________________________
// Function used for substitution decryption

void SubDecrypt(char *message, char *encryptKey)
{
int iteration;
int iteration_Num_Two = 0;
int letter;
//display the message to enter encryption key
printf("Enter Encryption Key: \n");
//Input the Encryption key
scanf("%s", encryptKey);
//loop will continue till message reaches to end
for (iteration = 0; message[iteration] != '0'; iteration++)
{
   //assign the first character of message to letter
letter = message[iteration];
//check the letter is between 'A' to 'Z' i.e/ upper case character or not
if (letter >= 'A' && letter <= 'Z')
{ //move the letter to 32 characters back
letter = letter - 32;
}
//after subtraction if the letter lies in the range 65 to 90(inclusive)
if (letter >= 65 && letter <= 90)
{
//loop will continue from 0 to 26
for (iteration_Num_Two = 0; iteration_Num_Two < 27; iteration_Num_Two++)
{
   //check if the message[iteration] and encryptKey[iteration_Num_Two] will equal then terminate the loop
if (message[iteration] == encryptKey[iteration_Num_Two])
{
break;
}
}
//set the message[iteration] to the value of iteration_Num_Two+'A'(uppercase) i.e/ 65+iteration_Num_Two
message[iteration] = 'A' + iteration_Num_Two;
  
}
//display the message
printf("%s\n", message);

}
//display the cipher text
printf("CipherText message: %s\n", message);
//display the encryptKey
printf("%s\n", encryptKey);
}

// End Function Void SubDecrypt
//_________________________________________________________________________________________________________________________________________________

// Function used for rotation decryption without using a key

void RotDecrypt_Without_Key(char *message, int key) {
//display a message
printf("Enter ciphertext to decrypt: \n");
  
int iteration;
char letter;
int count = 1;
//loop runs from 1 to 25
for (count = 1; count <26; count++)
{
//loop will continue till message reaches to end
for(iteration = 0; message[iteration] != '\0'; ++iteration)
{
   //assign each character of message to letter
letter = message[iteration];
key = 1; //assign key to 1
//check whetehr the letter is between A to Z (UPPERCASE CHARACTER)
if(letter >= 'A' && letter <= 'Z')
{
   //shift the letter one step back
letter = letter - key;
//after subtracting the key from letter if it goes beyond A
//then it will assgn the letter to Z (cyclic process)
if(letter < 'A'){
letter = letter + 'Z' - 'A' + 1;
}
//REASSIGN THE changed letter to message[iteration]
message[iteration] = letter;
}
  
//check whetehr the letter is between A to Z (UPPERCASE CHARACTER)
else if(letter >= 'a' && letter <= 'z'){
letter = letter - key;   //shift the letter one step back
//after subtracting the key from letter if it goes beyond a
//then it will assgn the letter to z (cyclic process)
if(letter < 'a'){
letter = letter + 'z' - 'a' + 1;
}
//REASSIGN THE changed letter to message[iteration]
message[iteration] = letter;
}
//increse the valeu of key by 1
key = key++;
}
//display the plain text
printf("Plaintext message: %s\n", message);
  
}
  
}

// End Function Void RotDecrypt_Without_Key

Add a comment
Know the answer?
Add Answer to:
Question: Please Provide Comments on each Line of code explaining what the C Function is doing throughout the code. // Function used for substitution encryption                     void SubEncrypt(cha...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple...

    Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple encryption methods. It works by shifting all letters in the original message (plaintext) by a certain fixed amount (the amounts represents the encryption key). The resulting encoded text is called ciphertext. Example Key (Shift): 3 Plaintext: Abc Ciphertext: Def Task Your goal is to implement a Caesar cipher program that receives the key and an encrypted paragraph (with uppercase and lowercase letters, punctuations, and...

  • This code should be Runnable on MARS (MIPS Assembler and Runtime Simulator) IDE Convert the following...

    This code should be Runnable on MARS (MIPS Assembler and Runtime Simulator) IDE Convert the following c code into mips #include <stdio.h> #include <string.h> char cipherText[200] = "anything"; int countNumberOfCharInCipher(char*); int countNumberOfCharInCipher(char* cText) { return strlen(cText);    } int countSpaces(int numberOfChar, char input[]) { int spaceCounter =0; for(int i=0; i < numberOfChar; i++) { if(input[i] == 32) spaceCounter++; } return spaceCounter; } void decrypt(int numberOfChar, int key, char * cipherText, char * plainText) { int j = 0; int i =0;...

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util...

    Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util.*; import java.lang.*; /** * * @author STEP */ public class ShiftCipher { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); String plainText; System.out.print("Please enter your string: "); // get message plainText = input.nextLine(); System.out.print("Please enter your shift cipher key: "); // get s int s = input.nextInt(); int...

  • USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is...

    USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is one of the simplest encryption techniques in the field of cryptography. It is a cipher in which each letter in a plain text message is replaced by a letter some fixed number of positions up the alphabet (i.e., by right shifting the alphabetic characters in the plain text message). For example, with a right shift of 2, ’A’ is replaced by ’C’, ’B’ is...

  • C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string usi...

    C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string using the RSA algorithm (C90 language only). It can contain ONLY the following libraries: stdio, stdlib, math and string. I want to use the following function prototypes to try and implement things: /*Check whether a given number is prime or not*/ int checkPrime(int n) /*to find gcd*/ int gcd(int a, int h) void Encrypt(); void Decrypt(); int getPublicKeys(); int getPrivateKeys();...

  • Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D....

    Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...

  • Write helpful comments for the following code: use Vigenere cipher tech to encrypt and decrypt message...

    Write helpful comments for the following code: use Vigenere cipher tech to encrypt and decrypt message The code: #include<stdio.h> #include <stdlib.h> char arr[26][26]; char message[22], key[22], emessage[22], retMessage[22]; int findRow(char); int findColumn(char); int findDecRow(char, int); int main() { int i = 0, j, k, r, c; k = 96; for (i = 0; i<26; i++) { k++; for (j = 0; j<26; j++) { arr[i][j] = k++; if (k == 123) k = 97; } } printf("\nEnter message\n"); fgets(message, 22,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT