Question

In: Computer Science

C Programming Language Please Given a string S and keyword string K, encrypt S using keyword...

C Programming Language Please

Given a string S and keyword string K, encrypt S using keyword Cipher algorithm.

Note: The encryption only works on alphabets. Numbers and symbols such as 1 to 9, -, &, $ etc remain unencrypted.

Input:

    Zombie Here

    secret

    where:

  • First line represents the unencrypted string S.
  • Second line represents the keyword string K.

Output:

    ZLJEFT DTOT

Explanation: We used "secret" keyword there.

  • Plain Text: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z, When "secret" keyword is used, the new encrypted text becomes
  • Encrypting: S E C R T A B D F G H I J K L M N O P Q U V W X Y Z This means 'A' means 'S', 'B' means 'E' and 'C' means 'C' and so on.

Solutions

Expert Solution

Here I am solving above encryption problem in C language.see below.

encrypted_string.c

#include<stdio.h>
#include<string.h>
int main(){
   char msg[10000],key[100];
   printf("Enter message: ");      // taking input message for encryption
   gets(msg);
   printf("Enter keyword: ");         // taking key as input here
   gets(key);
   strupr(key);                   // converting to upper case
   strupr(msg);                   // both msg and key
   char alphabet[26];
   int ind=0,i;
   for(i=65;i<91;i++)
   {                           // taking alphabets in UPPER case
       char c=i;
       alphabet[i-65]=c;  
   }
   char encrypted[10000];   
   strcpy(encrypted,key);
   strcat(encrypted,alphabet); // merging alphabets and encrypted key
   //printf("%s",encrypted);
   int k=0,j;
   // converting to encrypted one by removing duplicates in string
   char c='*';
   for(i=0;encrypted[i];i++)
    {
       if(!(encrypted[i]==c))
       {
           for(j=i+1;encrypted[j];j++)
            {
               if(encrypted[i]==encrypted[j])
                   encrypted[j]=c;
          
            }  
       }
    }

    for(i=0;encrypted[i];i++)
    {
        encrypted[i]=encrypted[i+k];

        if(encrypted[i]==c)
        {
          k++;
          i--;
        }
       
    }

   // printing resultant encrypted string.   
   for(i=0;i<strlen(msg);i++)
   {
       if(isalpha(msg[i])) // checking only alphabets
       {
           int index=(msg[i])-65;
           printf("%c",encrypted[index]);   // printing each character
       }
       else
           printf("%c",msg[i]);  
   }
      
   return 0;
}

Code - Images:-

output:-

Thank you..!! Please do upvote..!!


Related Solutions

Programming Language C++ Encrypt a text file using Caesar Cipher. Perform the following operations: Read the...
Programming Language C++ Encrypt a text file using Caesar Cipher. Perform the following operations: Read the console input and create a file. ['$' character denotes end of content in file.] Close the file after creation. Now encrypt the text file using Caesar Cipher (Use key value as 5). Display the contents of the updated file. #include <iostream> using namespace std; int main() { // write code here }
in C programming language char character [100] = "hello"; a string array variable It is given....
in C programming language char character [100] = "hello"; a string array variable It is given. By writing a function called TranslateString, By accessing the pointer address of this given string, returning the string's address (pointer address) by reversing the string Write the function and use it on the main function. Function void will not be written as. Return value pointer address it will be. Sweat operation on the same variable (character) It will be made. Declaration of the function...
Using playfair cipher, encrypt the plaintext “SUCCESS” using the keyword “MIDTERMEXAM”
Using playfair cipher, encrypt the plaintext “SUCCESS” using the keyword “MIDTERMEXAM”
(a) Use Vigenere cipher to encrypt the message “United States Constitution” using the keyword      “covid” Given...
(a) Use Vigenere cipher to encrypt the message “United States Constitution” using the keyword      “covid” Given that the Vigenere cipher of part (a) with the same keyword was used to produce the ciphertext: VFPUSVSNBVRCNQW Find the plaintext message.        
In C++ Consider the language L = { s$s' : s is a possibly empty string...
In C++ Consider the language L = { s$s' : s is a possibly empty string of characters other than $ , s' = reverse( s )} as defi ned in Chapter 6 . Write a recognition algorithm for this language that uses both a queue and a stack. Thus, as you traverse the input string, you insert each character of s into a queue and each character of s' into a stack. Assume that each input string contains exactly...
in the c programming language input is given in the form The input will be of...
in the c programming language input is given in the form The input will be of the form [number of terms] [coefficient k] [exponent k] … [coefficient 1] [exponent 1] eg. 5 ─3 7 824 5 ─7 3 1 2 9 0 in this there are 5 terms with -3x^7 being the highest /* Initialize all coefficients and exponents of the polynomial to zero. */ void init_polynom( int coeff[ ], int exp[ ] ) { /* ADD YOUR CODE HERE...
Write a C program that will read a character string and then encrypt the string based...
Write a C program that will read a character string and then encrypt the string based on one of the 3 different encryption methods. The type of encryption is to be selected by the user. Encryption method 1: Swapping by position. Characters in the array are swapped with the opposite characters based on their position in the string. Example: Input string – apple. Encrypted string – elppa Method: The first character ‘a’ and the last character ‘e’ – swap their...
IN PROGRAMMING LANGUAGE C -I am trying to alphbetize a string in descending or to EX...
IN PROGRAMMING LANGUAGE C -I am trying to alphbetize a string in descending or to EX INPUT: B C D A OUTPUT: D C B A #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char*argv[]) {         int MAX = 100000;         int i =0;         int k =0;         int j =0;         char array[MAX];         char split[] = " ,.-!?()0123456789";         int n = 0;         char second[MAX];         printf("Please enter in a String: ");...
Write a DFA simulator using the C++ programming language. Please refer to the following UDACITY website...
Write a DFA simulator using the C++ programming language. Please refer to the following UDACITY website if you do knot know C++. This is a free online tutorial for learning C++. Read your DFA from a textfile. First line contains a list of the final states (as integers), separated by a space. Rest of file contains the transitions in form: startstate, blank, symbol read, blank, tostate Prompt user for name of file. From there, program prompts the user for strings...
Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private»...
Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private» IsAuthenticated : bool + «C# property, setter absent» SIN : string + «C# property, setter absent» Name : string Methods + «Constructor» Person(name : string, sin : string) + Login(password : string) : void + Logout() : void + ToString() : string Transaction Class Properties + «C# property, setter absent » AccountNumber : string + «C# property, setter absent» Amount : double + «C#...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT