answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Maksim231197 [3]
2 years ago
12

In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program

will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters 1. Your program must compile and run from the command line. 2. Input the required file names as command line parameters. Your program may NOT prompt the user to enter the file names. The first parameter must be the name of the encryption key file, as described below. The second parameter must be the name of the file to be encrypted, as also described below. The sample run command near the end of this document contains an example of how the parameters will be entered. 3. Your program should open the two files, echo the processed input to the screen, make the necessary calculations, and then output the ciphertext to the console (terminal) screen in the format described below. Note: If the plaintext file to be encrypted doesn't have the proper number (512) of alphabetic characters, pad the last block as necessary with the letter 'X'. Make sure
Computers and Technology
2 answers:
skad [1K]2 years ago
5 0

Answer:

code is written in c++ below

Explanation:

// C++ code to implement Vigenere Cipher

#include<bits/stdc++.h>

using namespace std;

// This function generates the key in

// a cyclic manner until it's length isi'nt

// equal to the length of original text

string generateKey(string str, string key)

{

int x = str.size();

for (int i = 0; ; i++)

{

if (x == i)

i = 0;

if (key.size() == str.size())

break;

key.push_back(key[i]);

}

return key;

}

// This function returns the encrypted text

// generated with the help of the key

string cipherText(string str, string key)

{

string cipher_text;

for (int i = 0; i < str.size(); i++)

{

// converting in range 0-25

int x = (str[i] + key[i]) %26;

// convert into alphabets(ASCII)

x += 'A';

cipher_text.push_back(x);

}

return cipher_text;

}

// This function decrypts the encrypted text

// and returns the original text

string originalText(string cipher_text, string key)

{

string orig_text;

for (int i = 0 ; i < cipher_text.size(); i++)

{

// converting in range 0-25

int x = (cipher_text[i] - key[i] + 26) %26;

// convert into alphabets(ASCII)

x += 'A';

orig_text.push_back(x);

}

return orig_text;

}

// Driver program to test the above function

int main()

{

string str = "GEEKSFORGEEKS";

string keyword = "AYUSH";

string key = generateKey(str, keyword);

string cipher_text = cipherText(str, key);

cout << "Ciphertext : "

<< cipher_text << "\n";

cout << "Original/Decrypted Text : "

<< originalText(cipher_text, key);

return 0;

}

solniwko [45]2 years ago
4 0

Answer:

C code is given below

Explanation:

// Vigenere cipher

#include <ctype.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

/**

* Reading key file.

*/

char *readFile(char *fileName) {

   FILE *file = fopen(fileName, "r");

   char *code;

   size_t n = 0;

   int c;

   if (file == NULL) return NULL; //could not open file

   code = (char *)malloc(513);

   while ((c = fgetc(file)) != EOF) {

      if( !isalpha(c) )

          continue;

      if( isupper(c) )

          c = tolower(c);

      code[n++] = (char)c;

   }

   code[n] = '\0';

  fclose(file);

   return code;

}

int main(int argc, char ** argv){  

   // Check if correct # of arguments given

   if (argc != 3) {

       printf("Wrong number of arguments. Please try again.\n");

       return 1;

   }

 

  // try to read the key file

  char *key = readFile(argv[1]);

  if( !key ) {

      printf( "Invalid file %s\n", argv[1] );

      return 1;

  }

 

  char *data = readFile(argv[2]);

  if( !data ) {

      printf("Invalid file %s\n", argv[2] );

      return 1;

  }

 

   // Store key as string and get length

   int kLen = strlen(key);

  int dataLen = strlen( data );

 

  printf("%s\n", key );

  printf("%s\n", data );

 

  int paddingLength = dataLen % kLen;

  if( kLen > dataLen ) {

      paddingLength = kLen - dataLen;

  }

  for( int i = 0; i < paddingLength && dataLen + paddingLength <= 512; i++ ) {

      data[ dataLen + i ] = 'x';

  }

 

  dataLen += paddingLength;

 

   // Loop through text

   for (int i = 0, j = 0, n = dataLen; i < n; i++) {          

       // Get key for this letter

       int letterKey = tolower(key[j % kLen]) - 'a';

     

       // Keep case of letter

       if (isupper(data[i])) {

           // Get modulo number and add to appropriate case

           printf("%c", 'A' + (data[i] - 'A' + letterKey) % 26);

         

           // Only increment j when used

           j++;

       }

       else if (islower(data[i])) {

           printf("%c", 'a' + (data[i] - 'a' + letterKey) % 26);

           j++;

       }

       else {

           // return unchanged

           printf("%c", data[i]);

       }

      if( (i+1) % 80 == 0 ) {

          printf("\n");

      }

   }

 

   printf("\n");

 

   return 0;

}

You might be interested in
Enter an input statement using the input function at the shell prompt. When the prompt asks you for input, enter a number. Then,
Pavel [41]

Answer:

<u>Explanation:</u>

An input statement using the input function at the shell prompt is as follows:

If a prompt asks for a input, a number is to be added

num = input ('Number: ')

num = num + 1

print(num)

Explanation of results: This gives error at line num= num + 1 as cannot convert int object to str implicitly

8 0
2 years ago
What is the argument in this function =AVERAGE(F3:F26)
monitta
The argument for the function would be answer "D".
5 0
2 years ago
Replace any alphabetic character with '_' in 2-character string passCode. Ex: If passCode is "9a", output is: 9_
oksian1 [2.3K]

Answer:

if(isalpha(passCode[0]))

{

passCode[0] = '_';

}

if(isalpha(passCode[1]))

{

passCode[1] = '_';  

}

         

Explanation:

The first if statement uses isalpha() function which checks if the character passed in this function is an alphabet. If the character stored in 0-th position (which is the first position whose index is 0) of the variable passCode is an alphabet then it is replaced with the '_'

The next if statement checks if the second character in the passCode variable is an alphabet. This means the function isalpha() checks if the character stored in second position (index 1) of the variable passCode is an alphabet then it is replaced with the '_'

The  complete activity with this chunk of code added and the output is attached in a screen shot.

4 0
2 years ago
When using preventative insecticides which holiday period should trigger an application?
Savatey [412]
Spring break around Easter I would believe
4 0
2 years ago
Read 2 more answers
Create a custom list using cells A2 A12.
Dafna1 [17]

Answer:

To create a list of the cells A2 to A12, convert the A2: A12 range to a table, then select the data validation tab, input list as the type and the name of the A2:A12 range table, and then click ok. This list can now be used as a validation list in another column or worksheet.

Explanation:

Microsoft Excel provides the power of tables and list for categorized data and data validation.

7 0
2 years ago
Other questions:
  • In three to five sentences, describe whether or not files should be deleted from your computer.
    13·2 answers
  • Shirley was unsure about what career to go into. Her high school counselor suggested a personal assessment to point out Shirley’
    12·2 answers
  • The basic components of cartridges and shotshells are similar. Shot pellets and a bullet are examples of which basic component?
    13·1 answer
  • Which act was used to penalize Sara? Sara was found to be in possession of a controlled substance for which she had no justifica
    5·1 answer
  • Jesse would like to modify the table that he has inserted into a Word document by making the first row a single header cell.
    15·2 answers
  • Distinguish multiple inheritance and selective inheritance in oo concepts.
    14·1 answer
  • A network design engineer has been asked to design the IP addressing scheme for a customer network. The network will use IP addr
    6·1 answer
  • Write a generator function named count_seq that doesn't take any parameters and generates a sequence that starts like this: 2, 1
    5·1 answer
  • Select the described workplace culture from the drop-down menu.
    9·2 answers
  • Spark is electrical discharge in air, while air is mix of variety of gases what particles conduct electricity in gas
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!