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 or Python code to implement Shift cipher(Encryption and Decryption) and test your code on given plaintext. Your code must meet following conditions.

  1. (5 points) User must enter the value of key from command prompt and print it at command prompt.
  2. (2.5 points) Print the cipher text and the plaintext at the command prompt after encryption and decryption.
  3. (2.5 points) Test your algorithm for 5 different key values and submit your screen shot of command prompt input and outputs.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please let me know if anything is required. I am happy to help you.

Code in java :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


class Main
{
// Encrypts plain text using a shift cipher
public static StringBuffer encrypt(String text, int s)
{
StringBuffer result= new StringBuffer();
  
//loop to travel the string
for (int i=0; i<text.length(); i++)
{
if(text.charAt(i)!=' ') //condition to check the space in the string
{
  
if (Character.isUpperCase(text.charAt(i))) //condition to check the character is capital letter
{
//shifting the char using the given key
char ch = (char)(((int)text.charAt(i) +
s - 65) % 26 + 65);
result.append(ch); //after encryption adding the character in result string
}
else //condition to check the character is small letter
{
//shifting the char using the given key
char ch = (char)(((int)text.charAt(i) +
s - 97) % 26 + 97);
result.append(ch); //after encryption adding the character in result string
}
}
else
{
result.append(' '); //after encryption adding the space character in result string
}
}
return result; //returning the final result
}
  
// Decrypts cipher text using a shift cipher
public static StringBuffer decrypt(StringBuffer text, int s)
{
StringBuffer result= new StringBuffer();
  
//loop to travel the string
for (int i=0; i<text.length(); i++)
{
if(text.charAt(i)!=' ') //condition to check the space in the string
{
  
if (Character.isUpperCase(text.charAt(i))) //condition to check the character is capital letter
{
//shifting the char using the given key
char ch = (char)(((int)text.charAt(i) +
s - 65) % 26 + 65);
result.append(ch); //after decryption adding the character in result string
}
else //condition to check the character is small letter
{
//shifting the char using the given key
char ch = (char)(((int)text.charAt(i) +
s - 97) % 26 + 97);
result.append(ch); //after decryption adding the character in result string
}
}
else
{
result.append(' '); //after decryption adding the space character in result string
}
}
return result; //returning the final result
}
  
// Driver code
public static void main(String[] args) throws IOException
{
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));

// Reading the plain_text
System.out.print("Enter plain text : ");
String plain_text = reader.readLine();
  
//reading the key
Scanner in = new Scanner(System.in);
System.out.print("Enter key : ");
int key = in.nextInt();

System.out.println("Key you entered is : " +key);
  
System.out.println("\n ***** After Encryption *****");
System.out.println("Plain Text is : " + plain_text);
  
//calling Encryption
StringBuffer cipher_text = encrypt(plain_text, key);
System.out.println("Cipher Text is : " + cipher_text);
  
System.out.println("\n ***** After Decryption *****");
System.out.println("Cipher Text is : " + cipher_text);
key = 26 - key;
  
//calling Decryption
System.out.println("Plain Text is : " + decrypt(cipher_text, key));
  
  
}
}

Test case 1 :

Test 2:

Test 3:

Test 4:

Test 5:

Test 6:

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

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

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

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

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

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

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

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

  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

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