Question

The given plaintext is “Feistel cipher structure uses the same algorithm for both encryption and decryption”....

The given plaintext is “Feistel cipher structure uses the same algorithm for both encryption and decryption”. Write Java code to implement Shift cipher (Encryption and Decryption) and test your code on given plaintext. Your code must meet following conditions.

1. User must enter the value of key from command prompt and print it at command prompt.

2. Print the cipher text and the plaintext at the command prompt after encryption and decryption.

3. Test your algorithm for 5 different key values and please give screenshots of command prompt input and outputs.

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

import java.util.Scanner;
public class ShiftCipherText {
   static String encrypt(String s, int k) {
       String en = "";
       char ch;
       int x[] = new int[s.length()];
       for(int i = 0; i < s.length(); i++) {
           x[i] = s.charAt(i) - 65;
       }
       for(int i = 0; i < s.length(); i++) {
           x[i] = (x[i] + k) % 26;
           ch = (char)(x[i] + 65);
           en = en.concat(Character.toString(ch));
       }
       return en;
   }
   static String decrypt(String en, int k) {
       String dec = "";
       char ch;
       int y[] = new int[en.length()];
       for(int i = 0; i < en.length(); i++) {
           y[i] = en.charAt(i) - 65;
       }
       for(int i = 0; i < en.length(); i++) {
           y[i] = (y[i] + 26 - k) % 26;
           ch = (char)(y[i] + 65);
           dec = dec.concat(Character.toString(ch));
       }
       return dec;
   }

   public static void main(String[] args) {
       int k;
       String s, en, dec;
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the text to encode(all uppercase characters): ");
       s = sc.nextLine();      
       System.out.print("Enter the key( 0 - 25): " );
       k = sc.nextInt();
      
       System.out.println("Key: " + k);
       en = encrypt(s, k);
       System.out.println("Cipher Text: " + en);
       dec = decrypt(en, k);
       System.out.println("Plain Text: " + dec);      

   }

}

Add a comment
Know the answer?
Add Answer to:
The given plaintext is “Feistel cipher structure uses the same algorithm for both encryption and decryption”....
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
  • Creating a Vigenère Cipher Encryption/Decryption in Assembly Language NASM/YASM With these instructions so far we created...

    Creating a Vigenère Cipher Encryption/Decryption in Assembly Language NASM/YASM With these instructions so far we created some variables for the data and the outputs for them but are very confused on how to integrate the cipher portion so help would be appreciated. As seen in the picture below we are supposed to use a Vigenere cipher which uses key and plaintext variables in nasm/yasm assembly. The key is extended to the size of the text and then for each letter...

  • 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...

  • Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple...

    Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple encryption methods. It works by shifting all letters in the original message (plaintext) by a certain fixed amount (the amounts represents the encryption key). The resulting encoded text is called ciphertext. Example Key (Shift): 3 Plaintext: Abc Ciphertext: Def Task Your goal is to implement a Caesar cipher program that receives the key and an encrypted paragraph (with uppercase and lowercase letters, punctuations, and...

  • 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];                                                      ...

  • Final Project-1 A Modified XTS-AES Encryption and Decryption Input File: input. and key txt Time Limit:...

    Final Project-1 A Modified XTS-AES Encryption and Decryption Input File: input. and key txt Time Limit: No Problem Description Advanced Encryption Standard (AES) is a well-known symmetric block cipher in modern cryptography. It was published by NIST in 2001. Here, we design a modified XTS-AES as shown in Fig. 1. Please write two programs for encryption and decryption (e.g., encrypt.cpp and decrypt.cpp). To test the correctness of your encryption and decryption, two samples (one 256-bit plaintext and one 192-bit plaintext...

  • Decrypting the APCO cipher without the key. Decryption without the key is obviously a much more...

    Decrypting the APCO cipher without the key. Decryption without the key is obviously a much more difficult process. Indeed, the purpose of encryption is to make it as difficult as possible for anyone who does not know the key to read the plain text. We will be using an unsophisticated password cracking technique called a brute force attack. A brute force attack on the APCO cipher works by trying every possible four digit key (from 0000 to 9999) and keeping...

  • Write a Python program which implements the following two classical cryptosystem which we covered n class:...

    Write a Python program which implements the following two classical cryptosystem which we covered n class: a) Affine Cipher b) Vigenere Cipher Your program should consist of at least five functions: a) Two functions named encrypt, one for each of the two algorithms which accepts a lowercase alphabetical plaintext string and key as input and outputs a corresponding cipher text string. b) Two functions named decrypt, one for each of the two algorithms which accepts a lowercase alphabetical ciphertext string...

  • Write a javascript program which implements the following two classical cryptosystem which we covered in class:...

    Write a javascript program which implements the following two classical cryptosystem which we covered in class: Affine Cipher Vigenere Cipher Your program should consist of at least five functions: Two functions named encrypt, one for each of the two algorithms which accepts a lowercase alphabetical plaintext string and key as input and outputs a corresponding cipher text string. Two functions named decrypt, one for each of the two algorithms which accepts a lowercase alphabetical ciphertext string and a key as...

  • In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or...

    In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. Given an arbitrary cipher text file, you need to write a C++ program to find out the value of the shift, and decrypt the...

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