Question

In: Computer Science

Flow chart and IPO chart ( no handwritten please ) #include <stdio.h> #include <string.h> #include <conio.h>...

Flow chart and IPO chart ( no handwritten please )

#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>

char vs[26][26];

void encrypt(char input[], char key[], char cipher[]) {

char inputWithoutSpaces[50], repeatedKeyWord[50], tempCipher[50];

int cnt = 0, i = 0, keyLen = strlen(key), len3 = strlen(input);

// loop to remove the spaces from input & store in other char array inputWithoutSpaces
for (i = 0; i < len3; ++i) {
if (input[i] != ' ') {
inputWithoutSpaces[cnt++] = toupper(input[i]);
}
}
inputWithoutSpaces[cnt] = '\0';

int len1 = strlen(inputWithoutSpaces);

// loop to repeat the key until it becomes equal to the length of input without spaces
i = 0;
while (i < len1) {
repeatedKeyWord[i] = toupper(key[i % keyLen]);
i++;
}
repeatedKeyWord[i] = '\0';


// form the temp cipher
for (i = 0; i < len1; ++i) {
tempCipher[i] = vs[inputWithoutSpaces[i] % 'A'][repeatedKeyWord[i] % 'A'];
}

tempCipher[i] = '\0';

// modify the passed cipher by adding spaces in temp cipher wherever needed
cnt = 0;
for (i = 0; i < len3; ++i) {
if (input[i] == ' ')
cipher[i] = ' ';
else
cipher[i] = tempCipher[cnt++];
}
cipher[i] = '\0';


}

void decrypt(char cipher[], char key[], char plaintext[]) {

printf("%s\n", key);
char cipherWithoutSpaces[50], repeatedKeyWord[50], tempPlainText[50];

int cnt = 0, i = 0, keyLen = strlen(key), len3 = strlen(cipher);

// loop to remove the spaces from cipher & store in other char array cipherWithoutSpaces
for (i = 0; i < len3; ++i) {
if (cipher[i] != ' ') {
cipherWithoutSpaces[cnt++] = toupper(cipher[i]);
}
}
cipherWithoutSpaces[cnt] = '\0';

int len1 = strlen(cipherWithoutSpaces);

// loop to repeat the key until it becomes equal to the length of input without spaces
i = 0;
while (i < len1) {
repeatedKeyWord[i] = toupper(key[i % keyLen]);
i++;
}
repeatedKeyWord[i] = '\0';

// form the temp plaintext
cnt = 0;
for (i = 0; i < len1; ++i) {
for (int j = 0; j < 26; ++j) {
if (vs[repeatedKeyWord[i] % 'A'][j] == cipherWithoutSpaces[i])
tempPlainText[cnt++] = 'A' + j;
}
}
tempPlainText[cnt] = '\0';

// modify the passed plaintext by adding spaces in temp plaintext wherever needed
cnt = 0;
for (i = 0; i < len3; ++i) {
if (cipher[i] == ' ')
plaintext[i] = ' ';
else
plaintext[i] = tempPlainText[cnt++];
}
plaintext[i] = '\0';

}

int main(void) {

char selection;

char plaintext[50], cipher[50], key[10];

// making the table
for (int i = 0; i < 26; ++i)
for (int j = 0; j < 26; ++j)
vs[i][j] = ('A' + ((i + j) % 26));

// taking first selection
fflush(stdin);
printf("Enter e for encryption, d for decryption, x for exit: ");
scanf("%c", &selection);
  
// run loop till user enters 'x'
while (selection != 'x') {

// condition for encryption
if (selection == 'e') {

// taking plaintext
fflush(stdin);
printf("Enter the plaintext: ");
scanf("%50[a-zA-Z ]", plaintext);

// taking key
fflush(stdin);
printf("Enter the key: ");
scanf("%50[a-zA-Z ]", key);

// encrypting and displaying cipher
encrypt(plaintext, key, cipher);
fflush(stdin);
printf("Cipher text: %s\n\n", cipher);
}
else {

// taking encrypted text
fflush(stdin);
printf("Enter the encrpted text: ");
scanf("%50[a-zA-Z ]", cipher);

// taking key
fflush(stdin);
printf("Enter the key: ");
scanf("%50[a-zA-Z ]", key);

// decrypting and displaying plain text
decrypt(cipher, key, plaintext);
fflush(stdin);
printf("Plain Text: %s\n\n", plaintext);
}

fflush(stdin);
printf("Enter e for encryption, d for decryption, x for exit: ");
scanf("%c", &selection);
}

return 0;
}

Solutions

Expert Solution

Encrypt: based on the encrypt logic we can encrypt the text.

Decrypt: based on the decrypt logic, decode the text.

working code is given below.

please reply if you need more information.  

//Flow chart and IPO chart ( no handwritten please)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>

char vs[26][26];

void encrypt(char input[], char key[], char cipher[])
{
char inputWithoutSpaces[50], repeatedKeyWord[50], tempCipher[50];

int cnt = 0;
int i = 0, keyLen = strlen(key), len3 = strlen(input);
int len1;

// loop to remove the spaces from input & store in other char array inputWithoutSpaces
for (i = 0; i < len3; ++i)
{
if (input[i] != ' ')
{
inputWithoutSpaces[cnt++] = toupper(input[i]);
}
}
inputWithoutSpaces[cnt] = '\0';
len1 = strlen(inputWithoutSpaces);
// loop to repeat the key until it becomes equal to the length of input without spaces
i = 0;
while (i < len1)
{
repeatedKeyWord[i] = toupper(key[i % keyLen]);
i++;
}
repeatedKeyWord[i] = '\0';

// form the temp cipher
for (i = 0; i < len1; ++i)
{
tempCipher[i] = vs[inputWithoutSpaces[i] % 'A'][repeatedKeyWord[i] % 'A'];
}

tempCipher[i] = '\0';

// modify the passed cipher by adding spaces in temp cipher wherever needed
cnt = 0;
for (i = 0; i < len3; ++i)
{
if (input[i] == ' ')
cipher[i] = (' ');
else
cipher[i] = tempCipher[cnt++];
}
cipher[i] = '\0';


}//encrypt

void decrypt(char cipher[], char key[], char plaintext[])
{
char cipherWithoutSpaces[50], repeatedKeyWord[50], tempPlainText[50];
int cnt = 0,i = 0,keyLen = strlen(key),len3 = strlen(cipher),len1,j;
printf("%s\n", key);
// loop to remove the spaces from cipher & store in other char array cipherWithoutSpaces
for (i = 0; i < len3; ++i)
{
if (cipher[i] != ' ')
{
cipherWithoutSpaces[cnt++] = toupper(cipher[i]);
}
}
cipherWithoutSpaces[cnt] = '\0';

len1 = strlen(cipherWithoutSpaces);

// loop to repeat the key until it becomes equal to the length of input without spaces
i = 0;
while (i < len1)
{
repeatedKeyWord[i] = toupper(key[i % keyLen]);
i++;
}
repeatedKeyWord[i] = '\0';

// form the temp plaintext
cnt = 0;
for (i = 0; i < len1; ++i)
{
for (j = 0; j < 26; ++j)
{
if (vs[repeatedKeyWord[i] % 'A'][j] == cipherWithoutSpaces[i])
tempPlainText[cnt++] = ('A' + j);
}
}
tempPlainText[cnt] = '\0';

// modify the passed plaintext by adding spaces in temp plaintext wherever needed
cnt = 0;
for (i = 0; i < len3; ++i)
{
if (cipher[i] == ' ')
plaintext[i] =(' ');
else
plaintext[i] = tempPlainText[cnt++];
}
plaintext[i] = '\0';

} //decrypt


int main(void)
{

char selection;
char plaintext[50], cipher[50], key[10];
int i,j;
//making the table
for (i = 0; i < 26; ++i)
{
for (j = 0; j < 26; ++j)
{
vs[i][j] = ('A' + ((i + j) % 26));
}
}

// taking first selection
fflush(stdin);
printf("Enter e for encryption, d for decryption, x for exit: ");
scanf("%c", &selection);

// run loop till user enters 'x'
while (selection != 'x')
{

// condition for encryption
if (selection == 'e')
{

// taking plaintext
fflush(stdin);
printf("Enter the plaintext: ");
scanf("%50[a-zA-Z ]", plaintext);

// taking key
fflush(stdin);
printf("Enter the key: ");
scanf("%50[a-zA-Z ]", key);

// encrypting and displaying cipher
encrypt(plaintext, key, cipher);
fflush(stdin);
printf("Cipher text: %s\n\n", cipher);
}
else
{

// taking encrypted text
fflush(stdin);
printf("Enter the encrpted text: ");
scanf("%50[a-zA-Z ]", cipher);

// taking key
fflush(stdin);
printf("Enter the key: ");
scanf("%50[a-zA-Z ]", key);

// decrypting and displaying plain text
decrypt(cipher, key, plaintext);
fflush(stdin);
printf("Plain Text: %s\n\n", plaintext);
}

fflush(stdin);
printf("Enter e for encryption, d for decryption, x for exit: ");
scanf("%c", &selection);
}

return 0;
}


Related Solutions

construct c program flow chart #include <stdio.h> #include <math.h> #include <string.h> #define num 6 #define b...
construct c program flow chart #include <stdio.h> #include <math.h> #include <string.h> #define num 6 #define b 6 #define t 6 double bmical(double w, double h){ double o; double bmi; o = pow(h,2); bmi = w/o; return bmi; } double maxheartrate(int num1, int age){ double mhr; mhr = num1 - age; return mhr; } double heartratereserve(double mhr, double rhr){ double hrr; hrr = mhr - rhr; return hrr; } double minrange(int hrr, int rhr){ double mirt; mirt = (hrr * 0.7)...
please fix code #include <stdio.h> #include <stdlib.h> #include <string.h> // function declarations int getValidJerseyNumber(); int getValidRating();...
please fix code #include <stdio.h> #include <stdlib.h> #include <string.h> // function declarations int getValidJerseyNumber(); int getValidRating(); int main() { // declaring variables int size = 5; int jerseyNo[size]; int rating[size]; int i = 0, jno, rate; char option; /* Getting the inputs entered by the user * and populate the values into arrays */ for (i = 0; i < size; i++) { printf("Enter player %d's jersey number:", i + 1); jerseyNo[i] = getValidJerseyNumber(); printf("Enter player %d's rating:\n", i +...
Please paraphrase this c code #include <stdio.h> #include <stdlib.h> #include <string.h> void sortGrades(int arr[], int size,...
Please paraphrase this c code #include <stdio.h> #include <stdlib.h> #include <string.h> void sortGrades(int arr[], int size, int status, char names[][20]); void printer(int grades[], int size, char names[][20]); void sortNames(char arr[][20], int size, int status, int grades[]); void nameSearch(int grades[], int size, char names[][20]); void numSearch(int grades[], int size, char names[][20]); int main() { int i; int size; int option; do { printf("\n\nInput Number of Students or 0 to exit : "); scanf("%d", &size); if (size == 0) { break; }...
i need this program to also print out the number of combinations #include <stdio.h> #include <string.h>...
i need this program to also print out the number of combinations #include <stdio.h> #include <string.h> #define N 10 void generate(char *array, int n) {    if (n==0)    {        printf("%s\n",array);        return;    }    for (int i = 0; i < n; ++i)    {        // generate all of the permutations that end with the last element        generate(array, n-1);        // swap the element        char temp = array[n-1];...
#include <stdlib.h> #include <stdio.h> #include <string.h> void clrScreen(int lines){     int i = 0;     for( i =...
#include <stdlib.h> #include <stdio.h> #include <string.h> void clrScreen(int lines){     int i = 0;     for( i = 0; i < lines; ++i ){         printf("\n");     }     return; } void printRules(void){     printf("\t|*~*~*~*~*~*~*~*~*~ How to Play ~*~*~*~*~*~*~*~*~*~|\n");     printf("\t|   This is a 2 player game. Player 1 enters the   |\n");     printf("\t|   word player 2 has to guess. Player 2 gets a    |\n");     printf("\t|   number of guesses equal to twice the number    |\n");     printf("\t|   of characters. EX: If the word is 'example'    |\n");     printf("\t|   player 2 gets 14 guesses.                      |\n");     printf("\t|*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~|\n");     clrScreen(10);     return; } //------------------------------------------------------------------------------------------------------------ /*...
*****MUST ONLY USE****** #include <iostream> #include <fstream> #include <string.h> #include <stdio.h> Description The word bank system...
*****MUST ONLY USE****** #include <iostream> #include <fstream> #include <string.h> #include <stdio.h> Description The word bank system maintains all words in a text file named words.txt. Each line in the text file stores a word while all words are kept in an ascending order. You may assume that the word length is less than 20. The system should support the following three functions: Word lookup: to check whether a given word exists in the word bank. Word insertion: to insert a...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char *argv[]) {     FILE *myFile;...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char *argv[]) {     FILE *myFile;     char fname[20];     //int sum = 0;     int i, j, k, tmp =0;     int num = 0;     int mass = 0;     int count = 0;     int fuel = 0;     int total = 0;     int M[1000];     char ch;     char buffer[32];     printf(" Input the filename to be opened : ");     scanf("%s",fname);     myFile = fopen(fname, "r");     if(myFile == NULL)     {         printf("Can't open file\n");     } while(1)     {         ch =...
Use the given Strings.c and Strings.h module: Strings.c: #include "Strings.h" #include <string.h> #include<stdlib.h> #include<stdio.h> char* substring(char*...
Use the given Strings.c and Strings.h module: Strings.c: #include "Strings.h" #include <string.h> #include<stdlib.h> #include<stdio.h> char* substring(char* str, int iPos){ if(iPos > strlen(str)||iPos < 0)return (char*)NULL; char* substr; substr = &str[iPos]; return substr; } int charPosition(char* str, char c){ char* string = (char*)malloc(strlen(str)+1); int i; for(i = 0; i < strlen(str)+1; i++) { if(str[i] == c) { return i; } } return -1; } Strings.h: #include <string.h> /* substring - return a pointer to the substring beginning at the iPos-th position....
#include <stdio.h> #include <string.h> #include<stdlib.h> #include<conio.h> struct Bank_Account_Holder { int account_no; char name[80]; int balance; };...
#include <stdio.h> #include <string.h> #include<stdlib.h> #include<conio.h> struct Bank_Account_Holder { int account_no; char name[80]; int balance; }; int n; void accept(struct Bank_Account_Holder[], int); void display(struct Bank_Account_Holder[], int); void save(struct Bank_Account_Holder[], int); void load(struct Bank_Account_Holder[], int); int search(struct Bank_Account_Holder[], int, int); void deposit(struct Bank_Account_Holder[], int, int, int); void withdraw(struct Bank_Account_Holder[], int, int, int); int lowBalenquiry(int,int); void main(void) { clrscr(); struct Bank_Account_Holder data[20]; int choice, account_no, amount, index; printf("NHU Banking System\n\n"); printf("Enter the count of records: "); scanf("%d", &n); accept(data, n); do {...
I have the following code #include <stdio.h> #include<string.h> #define BUFLEN 128 typedef struct { int numPhrases;...
I have the following code #include <stdio.h> #include<string.h> #define BUFLEN 128 typedef struct { int numPhrases; }SyncInfo; char buffer[BUFLEN] ; char *phrases[] = {"educated", "educated cat", "educated lion", "serious person" , "serious panda","curious student","curious art student", "obnoxious web developer"}; char localBuffer[BUFLEN]; int allVowelsPresent; void *checker(void *param) { int a=0, e=0, i=0, o = 0, u= 0 ; int* n = (int*)param; // typecasting a void* to int* //printf("%d\n",*n); for (int q=0; q< (*n); ++q) { // dereferencing to get the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT