The objective of this programming assignment is to design and implement an encry
ID: 3776858 • Letter: T
Question
The objective of this programming assignment is to design and implement an encryption/decryption scheme. Consider the following encryption scheme: Initially, the plaintext is divided into two halves, left and right plaintext; each side is using Caesar's cipher with K1 and K2 respectively. The result of this encryption is interleaved character by character to generate an interleaved ciphertext. The ciphertext is then encrypted using Caesar's cipher with the key K3. Write a C/C++ program that takes as input a string and return the encrypted/decrypted message.Explanation / Answer
Code to copy:
-----------------------------------------------------------------------------------------------------------
// This is another program by a different approach with sample ouput
import java.io.*;
import java.util.*;
class feistel
{
public static void main(String args[]) throws Exception
{
int a[]=new int[20];
int left[]=new int[10];
int right[]=new int[10];
int key[]=new int[10];
int temp[]=new int[10];
int m[]=new int[10];
int i,k;
Scanner sc=new Scanner(System.in);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter length of string:");
int n=Integer.parseInt(br.readLine());
System.out.println("Enter plaintext:");
for(i=0;i<n;i++)
a[i]=sc.nextInt();
System.out.println("Enter key:");
for(i=0;i<(n/2);i++)
key[i]=sc.nextInt();
for(i=0;i<(n/2);i++)
left[i]=a[i];
for(int j=0;i<n;i++,j++)
right[j]=a[i];
System.out.println("Left string:");
for(i=0;i<(n/2);i++)
System.out.print(left[i]);
System.out.println();
System.out.println("Right string:");
for(i=0;i<(n/2);i++)
System.out.print(right[i]);
for(k=0;k<4;k++)
{
for(i=0;i<(n/2);i++)
{
if(key[i]==right[i])
temp[i]=0;
else
temp[i]=1;
}
for(i=0;i<(n/2);i++)
{
if(left[i]==temp[i])
m[i]=0;
else
m[i]=1;
}
for(i=0;i<(n/2);i++)
left[i]=right[i];
for(i=0;i<(n/2);i++)
right[i]=m[i];
System.out.println();
System.out.println("Round " + (k+1));
System.out.print("Left:");
for(i=0;i<(n/2);i++)
System.out.print(left[i]);
System.out.println();
System.out.print("Right:");
for(i=0;i<(n/2);i++)
System.out.print(right[i]);
}
System.out.println();
System.out.println("Encrypted string is:");
for(i=0;i<(n/2);i++)
{
System.out.print(left[i]);
}
System.out.print(" ");
for(i=0;i<(n/2);i++)
System.out.print(right[i]);
}
}
/*OUTPUT:
C:ins>java feistel
Enter length of string:
8
Enter plaintext:
0 1 0 1 0 1 0 1
Enter key:
1 0 1 0
Left string:
0101
Right string:
0101
Round 1
Left:0101
Right:1010
Round 2
Left:1010
Right:0101
Round 3
Left:0101
Right:0101
Round 4
Left:0101
Right:1010
Encrypted string is:
0101 1010
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.