Question

In: Computer Science

Also please add comments on the code and complete in C and also please use your...

Also please add comments on the code and complete in C and also please use your last name as key.

The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message.

Test Cases

The following messages will be given as the input as the test case to your program to check the accuracy of your program

-A HEALTHY ATTITUDE IS CONTAGIOUS BUT DONT WAIT TO CATCH IT FROM OTHERS.

-IF YOU CARRY YOUR CHILDHOOD WITH YOU YOU NEVER BECOME OLDER.

-FROM PRINCIPLES IS DERIVED PROBABILITY BUT TRUTH OR CERTAINTY IS OBTAINED ONLY FROM FACTS.

Solutions

Expert Solution

#include<stdio.h>
int stringSize(char *str){
   // string length function
   int len;
   for(len=0;str[len]!='\0';len++);
   return len;
}
void removeSpaces(char *initalString, char *str){
   // remove spaces from given string
   int len,spaces=0;
   for(len=0;initalString[len]!='\0';len++){
       if (initalString[len]==' '){
           spaces++;
           continue; }
       str[len-spaces]=initalString[len];
   }
   str[len-spaces]=initalString[len];
  
}
void generateKey(char* str, char* keyword, char*key)
{
   // generated repeated keyword of length str
   int size = stringSize(str);
   int keysize = stringSize(keyword);
   for (int i = 0; i<size ; i++)
   {
       key[i]=keyword[i%keysize];
   }
  
}

void cipherText(char* str, char* key,char* cipher_text)
{
   int size = stringSize(str);
   int spaces=0;
   for (int i = 0; i < size; i++)
   {
       // converting in range 0-25
       int x = (str[i] + key[i]) %26;
       // convert into alphabets(ASCII)
       x += 'A';
       cipher_text[i-spaces]=x;
   }
  
}

// This function decrypts the encrypted text
// and returns the original text
void originalText(char* cipher_text, char* key,char* decrypted)
{
  
   int size = stringSize(cipher_text);
   for (int i = 0 ; i < size; i++)
   {
       // converting in range 0-25
       int x = (cipher_text[i] - key[i] + 26) %26;
       // convert into alphabets(ASCII)
       x += 'A';
       decrypted[i]=x;
   }
  
}

int main()
{
   char initalString[1000] = "A HEALTHY ATTITUDE IS CONTAGIOUS BUT DONT WAIT TO CATCH IT FROM OTHERS";
   char str[1000];
   char keyword[1000] = "ANONYMOUS";
   char key[1000];
   char cipher_text[1000];
   char decrypted[1000];

   // Since its mentioned in quesion
   // You also have to skip the space between the words, while replicating the key to cover the entire message.
   removeSpaces(initalString, str); // remove spaces from initial string
   printf("String : %s\n", str);

   generateKey(str, keyword, key); // generate key of same length
   printf("Keyword: %s\n", key);

   cipherText(str, key, cipher_text); // generate cipher text
   printf("Ciphertext : %s\n", cipher_text);

   originalText(cipher_text, key, decrypted); // decrypted message
   printf("Decrypted Text : %s\n", decrypted);

   return 0;
}


Related Solutions

Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
Please Complete this C Code using the gcc compiler. Please include comments to explain each added...
Please Complete this C Code using the gcc compiler. Please include comments to explain each added line. /*This program computes the Intersection over Union of two rectangles as a percent: IoU = [Area(Intersection of R1 and R2) * 100 ] / [Area(R1) + Area(R2) - Area(Intersection of R1 and R2)] The answer will be specified as a percent: a number between 0 and 100. For example, if the rectangles do not overlap, IoU = 0%. If they are at the...
use repil.it intro to C-programin be sure Make code very basic and add good comments thank...
use repil.it intro to C-programin be sure Make code very basic and add good comments thank you 1-Write a program that requests 5 integers from the user and stores them in an array. You may do this with either a for loop OR by getting a string from stdin and using sscanf to store formatted input in each spot in the array. 2-Add a function to the program, called get_mean that determines the mean, which is the average of the...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final ArrayList<ItemOrder> itemOrder;    private double total = 0;    private double discount = 0;    ShoppingCart() {        itemOrder = new ArrayList<>();        total = 0;    }    public void setDiscount(boolean selected) {        if (selected) {            discount = total * .1;        }    }    public double getTotal() {        total = 0;        itemOrder.forEach((order) -> {            total +=...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog {...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog { String catalog_name; ArrayList<Item> list; Catalog(String cs_Gift_Catalog) { list=new ArrayList<>(); catalog_name=cs_Gift_Catalog; } String getName() { int size() { return list.size(); } Item get(int i) { return list.get(i); } void add(Item item) { list.add(item); } } Thanks!
Please do it in C++. Please comment on the code, and comments detail the run time...
Please do it in C++. Please comment on the code, and comments detail the run time in terms of total operations and Big O complexities. 1. Implement a class, SubstitutionCipher, with a constructor that takes a string with the 26 uppercase letters in an arbitrary order and uses that as the encoder for a cipher (that is, A is mapped to the first character of the parameter, B is mapped to the second, and so on.) Please derive the decoding...
Please write a complete C coding program (NOT C++) that has the following: (including comments) -...
Please write a complete C coding program (NOT C++) that has the following: (including comments) - declares two local integers x and y - defines a global structure containing two pointers (xptr, yptr) and an integer (z) - declares a variable (mst) by the type of previous structure - requests the values of x and y from the user using only one scanf statement - sets the first pointer in the struct to point to x - sets the second...
Please add comments to this code! Item Class: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! Item Class: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT