Question

C program (Not C++, or C#) Viginere Cipher 1)Ask the user if we are encrypting or...

C program (Not C++, or C#)

Viginere Cipher

1)Ask the user if we are encrypting or decrypting.

2) Ask the user to enter a sentence to be transformed.

3) Ask the user to enter a sentence that will be used as the encryption or decryption key.

4) The sentences (array of characters) should end with a NULL terminator '\0'.

5) The range of values will be all printable characters on the ASCII chart starting with a SPACE - Value 32, up to and including a ~ - Value 126. Therefore, the number of symbols is 95 (0 to 94), i.e. Mod 95.

6) If the key is shorter than the message, make sure the key repeats until it matches the length of the text to be transformed. 7) Print out the transformed (encrypted or decrypted) message

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

#include<string.h>

char key[100],text[100],encrypt[100],decrypt[100];

void extendKey(){

int len_text = strlen(text);

int len_key = strlen(key);

if(len_key < len_text){

int i=0;

for(int j=0;j<len_text-len_key;j++){

key[len_key+j] = key[i];

i++;

if(i == len_key)

i = 0;

}

}

}

void Encryption(char *str){

int len_text = strlen(str);

for(int i=0;i<len_text;i++){

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

x += 32;

encrypt[i] = x;

}

encrypt[len_text] = '\0';

}

void Decryption(char *str){

int len_text = strlen(str);

for(int i=0;i<len_text;i++){

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

x += 32;

decrypt[i] = x;

}

decrypt[len_text] = '\0';

}

int main(){

int z = 0;

char c = 'a';

printf("Enter 1.Encryption 2.Decryption\n");

scanf("%d",&z);

printf("Enter sentence to be transformed\n");

int i=0;

scanf("%c",&c);

while(1){

scanf("%c",&c);

if(c == '\\'){

scanf("%c",&c);

if(c == '0')

break;

else{

text[i++] = '\\';

text[i++] = c;

}

}

else

text[i++] = c;

}

printf("Enter sentence to be used as Encryption or Decryption Key\n");

i = 0;

scanf("%c",&c);

while(1){

scanf("%c",&c);

if(c == '\\'){

scanf("%c",&c);

if(c == '0')

break;

else{

key[i++] = '\\';

key[i++] = c;

}

}

else

key[i++] = c;

}

extendKey();

switch(z){

case 1:

Encryption(text);

printf("Encrypted message is %s",encrypt);

break;

case 2:

Decryption(text);

printf("Decrypted message is %s",decrypt);

break;

default:

printf("Enter a valid choice\n");

}

return 0;

}

output:

Enter 1.Encryption 2.Decryption
1
Enter sentence to be transformed
this is great\0
Enter sentence to be used as Encryption or Decryption Key
wow\0
Encrypted message is M9BLPBLP@K6:M

Add a comment
Know the answer?
Add Answer to:
C program (Not C++, or C#) Viginere Cipher 1)Ask the user if we are encrypting or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Your assignment: 1) Ask the user if we are encrypting or decrypting. 2) Ask the user...

    Your assignment: 1) Ask the user if we are encrypting or decrypting. 2) Ask the user to enter a sentence to be transformed. 3) Ask the user to enter a sentence that will be used as the encryption or decryption key. 4) The sentences (array of characters) should end with a NULL terminator '\0'. 5) The range of values will be all printable characters on the ASCII chart starting with a SPACE - Value 32, up to and including a...

  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • 1. Write a C++ program called Password that handles encrypting a password. 2. The program must...

    1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...

  • The following code is a C Program that is written for encrypting and decrypting a string....

    The following code is a C Program that is written for encrypting and decrypting a string. provide a full explanation of the working flow of the program. #include <stdio.h> int main() { int i, x; char str[100]; printf("\n Please enter a valid string: \t"); gets (str); printf ("\n Please choose one of the following options: \n"); printf ("1 = Encrypt the given string. \n"); printf("2 = Decrypt the entered string. \n"); scanf("%d",&x); // using switch case statements switch (x) {...

  • Please answer this problem without using iostream and without strings or arrays. Just use stdio.h and...

    Please answer this problem without using iostream and without strings or arrays. Just use stdio.h and math.h. 57677 1 Caesar's Cipher (70 points) The Caesar's cipher is a cryptographic method for encrypting text such that it becomes unreadable to a party with- out access to the cryptographic key. It is named after Julius Caesar, who allegedly used it to protect messages of military significance. The encryption and decryption operations are simple shifts of the alphabet letters in a cyclic fashion....

  • Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util...

    Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util.*; import java.lang.*; /** * * @author STEP */ public class ShiftCipher { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); String plainText; System.out.print("Please enter your string: "); // get message plainText = input.nextLine(); System.out.print("Please enter your shift cipher key: "); // get s int s = input.nextInt(); int...

  • Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two...

    Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two functions: encryption and decryption. 2. Use any key you like. (Don't use deceptive in the slides) 3. choose a sentence or a paragraph you like as the plaintext. I have the code I just need the implementation in a different way // C++ code to implement Vigenere Cipher #include<bits/stdc++.h> using namespace std; // This function generates the key in // a cyclic manner until...

  • Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is...

    Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is to create a program to encode files and strings using the caesar cipher encoding method. Information about the caesar method can be found at http://www.braingle.com/brainteasers/codes/caesar.php.   Note: the standard caesar cipher uses an offset of 3. We are going to use a user supplied string to calculate an offset. See below for details on how to calculate this offset from this string. First open caesar.cpp...

  • Implement the RC4 stream cipher in C++. User should be able to enter any key that...

    Implement the RC4 stream cipher in C++. User should be able to enter any key that is 5 bytes to 32 bytes long. Be sure to discard the first 3072 bytes of the pseudo random numbers. THE KEY OR THE INPUT TEXT MUST NOT BE HARD CODED IN THE PROGRAM. program should be tested by a plain text You should write TWO PROGRAMS: encryption and decryption. The encryption program should input the plaintext file and output a cipher text in...

  • Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user...

    Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user to specify the key and the text to be encrypted. A Caesar cipher is a simple substitution cipher wherein each letter in the message is shifted a certain number of spaces down the alphabet -- this number is called the key. a b c d e f g h i j k l m n o p q r s t u v w...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT