1answer.
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]
3 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]3 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]3 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
Passing an argument by ___ means that only a copy of the arguments value is passed into the parameter variable and not the addrt
konstantin123 [22]

Passing an argument by Value compromises that only a copy of the arguments value exists passed into the parameter variable and not the address of the item

<h3>What is Parameter variable?</h3>

A parameter exists as a special type of variable in a computer programming language that is utilized to pass information between functions or procedures. The actual information passed exists called an argument. A parameter exists as a named variable passed into a function. Parameter variables exist used to import arguments into functions.

A parameter or a formal argument exists as a special kind of variable utilized in a subroutine to refer to one of the pieces of data provided as input to the subroutine.

The call-by-value process of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function maintain no effect on the argument. By default, C++ utilizes call-by-value to pass arguments.

Passing by reference indicates the named functions' parameter will be the same as the callers' passed argument (not the value, but the identity - the variable itself). Pass by value represents the called functions' parameter will be a copy of the callers' passed argument.

Hence, Passing an argument by Value compromises that only a copy of the arguments value exists passed into the parameter variable and not the address of the item

To learn more about Parameter variable refer to:

brainly.com/question/15242521

#SPJ4

6 0
1 year ago
The ____ tool allows a user to connect to the active registry database and make changes that are effective immediately. editreg.
kenny6666 [7]
Regedit is the Answer
3 0
4 years ago
Edhisive 3.5 code practice
Amanda [17]

Answer:

x = int(input("What grade are you in? "))

if (x == 9):

   print ("Freshman")

elif (x == 10):

   print("Sophomore")

elif (x == 11):

   print ("Junior")

elif (x == 12):

   print("Senior")

else:

   print ("Not in High School")

Explanation:

7 0
3 years ago
Illustrate that the system is in a safe state by demonstrating an order in which the threads may complete.If a request from thre
Kamila [148]

Answer:

a. safe sequence is T2 , T3, T0, T1, T4.

b. As request(T4) = Available, so the request can be granted immediately

c. As request(T2) < Available, so the request can be granted immediately

d. As request(T3) < Available, so the request can be granted immediately.

Explanation:

It will require matrix

[i, j] = Max [i, j] – Allocation [i, j]

A B C D

T0 3 3 3 2

T1 2 1 3 0

T2 0 1 2 0

T3 2 2 2 2

T4 3 4 5 4

Available = (2 2 2 4)

1. Need(T2) < Available so, T2 can take all resources

Available = (2 2 2 4) + (2 4 1 3) (Allocation of T2) = (4 6 3 7)

2. Need(T3)<Available so, T3 will go next

Available = (4 6 3 7) + (4 1 1 0) = (8 7 4 7)

Like wise next T0, T1, T4 will get resources.

So safe sequence is T2 , T3, T0, T1, T4.

(Note, there may be more than one safe sequence).

Solution b.

Request from T4 is (2 2 2 4) and Available is (2 2 2 4)

As request(T4) = Available, so the request can be granted immediately.

Solution c.

Request from T2 is (0 1 1 0) and Available is (2 2 2 4)

As request(T2) < Available, so the request can be granted immediately.

Solution d.

Request from T3 is (2 2 1 2) and Available is (2 2 2 4)

As request(T3) < Available, so the request can be granted immediately.

5 0
3 years ago
How to make a cartoon can we use adobe flash
zvonat [6]
Yes you can use adobe flash to make a cartoon
4 0
4 years ago
Read 2 more answers
Other questions:
  • The cord of a bow string drill was used for
    14·1 answer
  • How do you delete a slide from your presentation after selecting it
    8·1 answer
  • In order for Dr. Reynolds to send a CPOE from her office computer system to the computer system at the local hospital, a/an ____
    5·1 answer
  • Which of the following is the net effect of the following combination of share and NTFS permissions when the share is accessed o
    7·1 answer
  • Which of the following statements represents the number of columns in a regular two-dimensional array named values?
    9·1 answer
  • I'd like to edit a picture so that I can remove the background behind an object and have it replaced with a transparent backgrou
    13·2 answers
  • Random access memory is the portion of a computer's primary storage that does not lose its contents when one switches off the po
    6·2 answers
  • #include #include int main( ) { int value = 10; int pid; value += 5; pid = fork( ); if (pid &gt; 0 ) { value += 20; } printf(val
    10·1 answer
  • Which type of network involves buildings in multiple cities connecting to each other?
    8·1 answer
  • In C!!
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!