Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to know what I did wrong in my code, it is not doing what I want it to do. Please arrange it so

I need to know what I did wrong in my code, it is not doing what I want it to do. Please arrange it so that it matches the specifications without changing the code I used so I can see where I went wrong.

Design and implement a program that encrypts messages using Vigenres cipher. Implement your program in a file called vigenere.c in a directory called vigenere. Your program must accept a single command-line argument: a keyword, k, composed entirely of alphabetical characters. If your program is executed without any command-line arguments, with more than one command-line argument, or with one command-line argument that contains any non-alphabetical character, your program should print an error (of your choice) and exit immediately, with main returning 1 (thereby signifying an error). Otherwise, your program must proceed to prompt the user for a string of plaintext, p, (as by a prompt for plaintext:) which it must then encrypt according to Vigenres cipher with k, ultimately printing the result (prepended with ciphertext:and ending with a newline) and exiting, with main returning 0. With respect to the characters in k, you must treat A and a as 0, B and b as 1, , and Z and z as 25. Your program must only apply Vigenres cipher to a character in p if that character is a letter. All other characters (numbers, symbols, spaces, punctuation marks, etc.) must be outputted unchanged. Moreover, if your code is about to apply the jthcharacter of k to the ith character of p, but the latter proves to be a non-alphabetical character, you must wait to apply that jthcharacter of k to the next alphabetical character in p; you must not yet advance to the next character in k. Your program must preserve the case of each letter in p.

#include #include #include #include #include int letter; int shift; int main(int argc, string argv[1]) {

if(argc != 2) printf("Invalid Entry. "); return 1; } string keys = argv[1]; plain_len = strlen(keys); for (int i = 0, keylength = strlen(argv[i]); i < keylength; i++) {

if ((keys[i] >= '0') && (keys[i] <= '9')) printf("you were supposed to enter a word with only letters. "); return 1; }

} keys[i] = toupper(keys[i]); } { string plaintext = get_string("plaintext: "); printf("ciphertext: "); int reference = 0; for (int i = 0, r = strlen(plaintext); i < r; i++ }

if (isalpha(plaintext[i]))

} { int keys = keys[reference]- 'A'

if ((plaintext>='A') && (plaintext<= 'Z')) { plaintext=(plaintext - 'A'); }

if ((plaintext >+ 'a') && (plaintext <= 'z')) { plaintext = (plaintext - 'a'); }

reference =(reference + 1); { printf("%c", plaintext[i]); } printf(" "); return 1; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions