SlideShare a Scribd company logo
CipherDriver.java
//package Unit_6;
import java.util.*;
public class CipherDriver {
public static void main(String[] args) {
int menu1, menu2;
Scanner input = new Scanner(System.in);
System.out.println("Enter (1) to encode a message");
System.out.println(" Enter (2) to decode a message");
System.out.println(" Enter (3) to exit");
menu1 = input.nextInt();
if (menu1 == 3){
System.exit(0);
}
if (menu1 == 1 ){
int n;
System.out.println(" Enter (1) for substitution cipher");
System.out.println(" Enter (2) for shuffle cipher");
System.out.println(" Enter (3) to exit");
menu2 = input.nextInt();
System.out.print(" Enter text to be encoded: ");
Scanner encodeText = new Scanner(System.in);
String encode_text = encodeText.nextLine();
if (menu2 == 3)
System.exit(0);
if (menu2 == 1){
System.out.print(" Enter shift value: ");
n = input.nextInt();
input.nextLine();
SubstitutionCipher sub = new SubstitutionCipher(n);
String encodedMessage = sub.encode(encode_text);
System.out.println("Encode Message: " + encodedMessage);
}
if (menu2 == 2){
System.out.print("Enter number of shuffles: ");
n = input.nextInt();
input.nextLine();
ShuffleCipher shuffleCipher = new ShuffleCipher(n);
String encodedText = shuffleCipher.encode(encode_text);
System.out.println("Encode Message: " + encodedText);
}
encodeText.close();
}
if (menu1 == 2){
int n;
System.out.println(" Enter (1) for substitution cipher");
System.out.println(" Enter (2) for shuffle cipher");
System.out.println(" Enter (3) to exit");
menu2 = input.nextInt();
System.out.print("Enter text to be decode: ");
Scanner decodeText = new Scanner(System.in);
String decode_text = decodeText.nextLine();
if (menu2 == 3)
System.exit(0);
if (menu2 == 1){
System.out.print("Enter shift value: ");
n = input.nextInt();
input.nextLine();
SubstitutionCipher substitution = new SubstitutionCipher(n);
String decodedText = substitution.decode(decode_text);
System.out.println("Decoded Message: " + decodedText);
}
if (menu2 == 2){
System.out.print("Enter number of shuffles: ");
n = input.nextInt();
input.nextLine();
ShuffleCipher shuffleCipher = new ShuffleCipher(n);
String decodedText = shuffleCipher.decode(decode_text);
System.out.println("Decoded Message: " + decodedText);
}
decodeText.close();
}
input.close();
}
}
ShuffleCipher.java
//package Unit_6;
// Create a class ShuffleCipher that implements the interface MessageEncoder
public class ShuffleCipher implements MessageEncoder, MessageDecoder {
// The constructor should have one parameter called n
private int n;
// The constructor which takes the shuffle value
public ShuffleCipher (int n){
this.n = n;
}
// Performs single shuffle
private String shuffle(String text){
int splitLetter;
if (text.length() % 2 == 0)
splitLetter = text.length() / 2;
else
splitLetter = ((text.length() + 1) / 2);
String first = text.substring(0, splitLetter);
String second = text.substring(splitLetter);
String shuffleText = "";
for(int i = 0, j = 0; i < first.length(); i++, j++){
shuffleText += first.charAt(i);
if(j < second.length())
shuffleText += second.charAt(i);
}
return shuffleText;
}
// Decodes the shuffled message
private String decodeShuffle(String text){
String firstHalf = "", secondHalf = "";
for(int i=0;i
Solution
CipherDriver.java
//package Unit_6;
import java.util.*;
public class CipherDriver {
public static void main(String[] args) {
int menu1, menu2;
Scanner input = new Scanner(System.in);
System.out.println("Enter (1) to encode a message");
System.out.println(" Enter (2) to decode a message");
System.out.println(" Enter (3) to exit");
menu1 = input.nextInt();
if (menu1 == 3){
System.exit(0);
}
if (menu1 == 1 ){
int n;
System.out.println(" Enter (1) for substitution cipher");
System.out.println(" Enter (2) for shuffle cipher");
System.out.println(" Enter (3) to exit");
menu2 = input.nextInt();
System.out.print(" Enter text to be encoded: ");
Scanner encodeText = new Scanner(System.in);
String encode_text = encodeText.nextLine();
if (menu2 == 3)
System.exit(0);
if (menu2 == 1){
System.out.print(" Enter shift value: ");
n = input.nextInt();
input.nextLine();
SubstitutionCipher sub = new SubstitutionCipher(n);
String encodedMessage = sub.encode(encode_text);
System.out.println("Encode Message: " + encodedMessage);
}
if (menu2 == 2){
System.out.print("Enter number of shuffles: ");
n = input.nextInt();
input.nextLine();
ShuffleCipher shuffleCipher = new ShuffleCipher(n);
String encodedText = shuffleCipher.encode(encode_text);
System.out.println("Encode Message: " + encodedText);
}
encodeText.close();
}
if (menu1 == 2){
int n;
System.out.println(" Enter (1) for substitution cipher");
System.out.println(" Enter (2) for shuffle cipher");
System.out.println(" Enter (3) to exit");
menu2 = input.nextInt();
System.out.print("Enter text to be decode: ");
Scanner decodeText = new Scanner(System.in);
String decode_text = decodeText.nextLine();
if (menu2 == 3)
System.exit(0);
if (menu2 == 1){
System.out.print("Enter shift value: ");
n = input.nextInt();
input.nextLine();
SubstitutionCipher substitution = new SubstitutionCipher(n);
String decodedText = substitution.decode(decode_text);
System.out.println("Decoded Message: " + decodedText);
}
if (menu2 == 2){
System.out.print("Enter number of shuffles: ");
n = input.nextInt();
input.nextLine();
ShuffleCipher shuffleCipher = new ShuffleCipher(n);
String decodedText = shuffleCipher.decode(decode_text);
System.out.println("Decoded Message: " + decodedText);
}
decodeText.close();
}
input.close();
}
}
ShuffleCipher.java
//package Unit_6;
// Create a class ShuffleCipher that implements the interface MessageEncoder
public class ShuffleCipher implements MessageEncoder, MessageDecoder {
// The constructor should have one parameter called n
private int n;
// The constructor which takes the shuffle value
public ShuffleCipher (int n){
this.n = n;
}
// Performs single shuffle
private String shuffle(String text){
int splitLetter;
if (text.length() % 2 == 0)
splitLetter = text.length() / 2;
else
splitLetter = ((text.length() + 1) / 2);
String first = text.substring(0, splitLetter);
String second = text.substring(splitLetter);
String shuffleText = "";
for(int i = 0, j = 0; i < first.length(); i++, j++){
shuffleText += first.charAt(i);
if(j < second.length())
shuffleText += second.charAt(i);
}
return shuffleText;
}
// Decodes the shuffled message
private String decodeShuffle(String text){
String firstHalf = "", secondHalf = "";
for(int i=0;i

More Related Content

Similar to CipherDriver.javapackage Unit_6;import java.util.;public cl.pdf

Modify before asshignment so that we can check input errors, etc.. P.pdf
Modify before asshignment so that we can check input errors, etc.. P.pdfModify before asshignment so that we can check input errors, etc.. P.pdf
Modify before asshignment so that we can check input errors, etc.. P.pdf
arihantplastictanksh
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
C# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdfC# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdf
fathimalinks
 
Trace the following part of codes step by step- Show exactly what it w.docx
Trace the following part of codes step by step- Show exactly what it w.docxTrace the following part of codes step by step- Show exactly what it w.docx
Trace the following part of codes step by step- Show exactly what it w.docx
gtameka
 
(I'm trying to make a menu that repeats unless you enter 4- How do I g.pdf
(I'm trying to make a menu that repeats unless you enter 4- How do I g.pdf(I'm trying to make a menu that repeats unless you enter 4- How do I g.pdf
(I'm trying to make a menu that repeats unless you enter 4- How do I g.pdf
aone2010
 
Java interface
Java interfaceJava interface
Java interface
Md. Tanvir Hossain
 
ch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.ppt
Mahyuddin8
 
can someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdfcan someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdf
vinaythemodel
 
Unit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdfUnit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdf
AnilkumarBrahmane2
 
Here is my code for a linefile editor Please help me figure out wh.pdf
Here is my code for a linefile editor Please help me figure out wh.pdfHere is my code for a linefile editor Please help me figure out wh.pdf
Here is my code for a linefile editor Please help me figure out wh.pdf
pratyushraj61
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
optokunal1
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
Coding Assignment Help
 
Image Recognition with Neural Network
Image Recognition with Neural NetworkImage Recognition with Neural Network
Image Recognition with Neural Network
Sajib Sen
 
delegates
delegatesdelegates
delegates
Owais Masood
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
aptcomputerzone
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdf
aroramobiles1
 
The java program that prompts user to enter a string and .pdf
  The java program that prompts user to  enter a string and .pdf  The java program that prompts user to  enter a string and .pdf
The java program that prompts user to enter a string and .pdf
DEEPAKSONI562
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
Gines Espada
 

Similar to CipherDriver.javapackage Unit_6;import java.util.;public cl.pdf (18)

Modify before asshignment so that we can check input errors, etc.. P.pdf
Modify before asshignment so that we can check input errors, etc.. P.pdfModify before asshignment so that we can check input errors, etc.. P.pdf
Modify before asshignment so that we can check input errors, etc.. P.pdf
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
C# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdfC# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdf
 
Trace the following part of codes step by step- Show exactly what it w.docx
Trace the following part of codes step by step- Show exactly what it w.docxTrace the following part of codes step by step- Show exactly what it w.docx
Trace the following part of codes step by step- Show exactly what it w.docx
 
(I'm trying to make a menu that repeats unless you enter 4- How do I g.pdf
(I'm trying to make a menu that repeats unless you enter 4- How do I g.pdf(I'm trying to make a menu that repeats unless you enter 4- How do I g.pdf
(I'm trying to make a menu that repeats unless you enter 4- How do I g.pdf
 
Java interface
Java interfaceJava interface
Java interface
 
ch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.ppt
 
can someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdfcan someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdf
 
Unit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdfUnit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdf
 
Here is my code for a linefile editor Please help me figure out wh.pdf
Here is my code for a linefile editor Please help me figure out wh.pdfHere is my code for a linefile editor Please help me figure out wh.pdf
Here is my code for a linefile editor Please help me figure out wh.pdf
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 
Image Recognition with Neural Network
Image Recognition with Neural NetworkImage Recognition with Neural Network
Image Recognition with Neural Network
 
delegates
delegatesdelegates
delegates
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdf
 
The java program that prompts user to enter a string and .pdf
  The java program that prompts user to  enter a string and .pdf  The java program that prompts user to  enter a string and .pdf
The java program that prompts user to enter a string and .pdf
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
 

More from ravikapoorindia

1.The Excavata includes taxa that are photosynthetic, parasitic, sym.pdf
1.The Excavata includes taxa that are photosynthetic, parasitic, sym.pdf1.The Excavata includes taxa that are photosynthetic, parasitic, sym.pdf
1.The Excavata includes taxa that are photosynthetic, parasitic, sym.pdf
ravikapoorindia
 
1. According to morphological species concept focus on external phys.pdf
1. According to morphological species concept focus on external phys.pdf1. According to morphological species concept focus on external phys.pdf
1. According to morphological species concept focus on external phys.pdf
ravikapoorindia
 
1)calcium(pH-dependent regulation of lysosomal calcium in macrophage.pdf
1)calcium(pH-dependent regulation of lysosomal calcium in macrophage.pdf1)calcium(pH-dependent regulation of lysosomal calcium in macrophage.pdf
1)calcium(pH-dependent regulation of lysosomal calcium in macrophage.pdf
ravikapoorindia
 
Viral genomes may be circular, as in the polyomaviruses, or linear, .pdf
Viral genomes may be circular, as in the polyomaviruses, or linear, .pdfViral genomes may be circular, as in the polyomaviruses, or linear, .pdf
Viral genomes may be circular, as in the polyomaviruses, or linear, .pdf
ravikapoorindia
 
True. gaps are the reason for electrical conductivity.Solution.pdf
True. gaps are the reason for electrical conductivity.Solution.pdfTrue. gaps are the reason for electrical conductivity.Solution.pdf
True. gaps are the reason for electrical conductivity.Solution.pdf
ravikapoorindia
 
This is an example of a Lewis Acid. The CO2 acts like an acid becaus.pdf
This is an example of a Lewis Acid. The CO2 acts like an acid becaus.pdfThis is an example of a Lewis Acid. The CO2 acts like an acid becaus.pdf
This is an example of a Lewis Acid. The CO2 acts like an acid becaus.pdf
ravikapoorindia
 
The Vestibular System, which is a contributed to our balance system .pdf
The Vestibular System, which is a contributed to our balance system .pdfThe Vestibular System, which is a contributed to our balance system .pdf
The Vestibular System, which is a contributed to our balance system .pdf
ravikapoorindia
 
The inherent risk for an assertion about a derivative is its suscept.pdf
The inherent risk for an assertion about a derivative is its suscept.pdfThe inherent risk for an assertion about a derivative is its suscept.pdf
The inherent risk for an assertion about a derivative is its suscept.pdf
ravikapoorindia
 
Solution I ) Average inventory = $610,000 5 = $122000Total Inven.pdf
Solution I ) Average inventory = $610,000  5 = $122000Total Inven.pdfSolution I ) Average inventory = $610,000  5 = $122000Total Inven.pdf
Solution I ) Average inventory = $610,000 5 = $122000Total Inven.pdf
ravikapoorindia
 
1 D2 the decrease in entropy of the system is offset by an incr.pdf
1 D2  the decrease in entropy of the system is offset by an incr.pdf1 D2  the decrease in entropy of the system is offset by an incr.pdf
1 D2 the decrease in entropy of the system is offset by an incr.pdf
ravikapoorindia
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
ravikapoorindia
 
NaCl + H2OSolutionNaCl + H2O.pdf
NaCl + H2OSolutionNaCl + H2O.pdfNaCl + H2OSolutionNaCl + H2O.pdf
NaCl + H2OSolutionNaCl + H2O.pdf
ravikapoorindia
 
Miller is US based investor and co-founder and current chairman of U.pdf
Miller is US based investor and co-founder and current chairman of U.pdfMiller is US based investor and co-founder and current chairman of U.pdf
Miller is US based investor and co-founder and current chairman of U.pdf
ravikapoorindia
 
Marijuana plant belongs to the genus Cannabis. It is native to the C.pdf
Marijuana plant belongs to the genus Cannabis. It is native to the C.pdfMarijuana plant belongs to the genus Cannabis. It is native to the C.pdf
Marijuana plant belongs to the genus Cannabis. It is native to the C.pdf
ravikapoorindia
 
InheritenceJava supports inheritance and thus, variables and metho.pdf
InheritenceJava supports inheritance and thus, variables and metho.pdfInheritenceJava supports inheritance and thus, variables and metho.pdf
InheritenceJava supports inheritance and thus, variables and metho.pdf
ravikapoorindia
 
It is the temporal lobe of cerebrum. It is situated beneath the late.pdf
It is the temporal lobe of cerebrum. It is situated beneath the late.pdfIt is the temporal lobe of cerebrum. It is situated beneath the late.pdf
It is the temporal lobe of cerebrum. It is situated beneath the late.pdf
ravikapoorindia
 
In cat,The ductus deferens also called the vas deferens leaves the t.pdf
In cat,The ductus deferens also called the vas deferens leaves the t.pdfIn cat,The ductus deferens also called the vas deferens leaves the t.pdf
In cat,The ductus deferens also called the vas deferens leaves the t.pdf
ravikapoorindia
 
LeadCarbonate PbCO3 is ionic compound. electrostaticforces.pdf
  LeadCarbonate  PbCO3 is ionic compound. electrostaticforces.pdf  LeadCarbonate  PbCO3 is ionic compound. electrostaticforces.pdf
LeadCarbonate PbCO3 is ionic compound. electrostaticforces.pdf
ravikapoorindia
 
Vo.pdf
   Vo.pdf   Vo.pdf
Lithium has 3 electrons. Since an s orbital only .pdf
                     Lithium has 3 electrons. Since an s orbital only .pdf                     Lithium has 3 electrons. Since an s orbital only .pdf
Lithium has 3 electrons. Since an s orbital only .pdf
ravikapoorindia
 

More from ravikapoorindia (20)

1.The Excavata includes taxa that are photosynthetic, parasitic, sym.pdf
1.The Excavata includes taxa that are photosynthetic, parasitic, sym.pdf1.The Excavata includes taxa that are photosynthetic, parasitic, sym.pdf
1.The Excavata includes taxa that are photosynthetic, parasitic, sym.pdf
 
1. According to morphological species concept focus on external phys.pdf
1. According to morphological species concept focus on external phys.pdf1. According to morphological species concept focus on external phys.pdf
1. According to morphological species concept focus on external phys.pdf
 
1)calcium(pH-dependent regulation of lysosomal calcium in macrophage.pdf
1)calcium(pH-dependent regulation of lysosomal calcium in macrophage.pdf1)calcium(pH-dependent regulation of lysosomal calcium in macrophage.pdf
1)calcium(pH-dependent regulation of lysosomal calcium in macrophage.pdf
 
Viral genomes may be circular, as in the polyomaviruses, or linear, .pdf
Viral genomes may be circular, as in the polyomaviruses, or linear, .pdfViral genomes may be circular, as in the polyomaviruses, or linear, .pdf
Viral genomes may be circular, as in the polyomaviruses, or linear, .pdf
 
True. gaps are the reason for electrical conductivity.Solution.pdf
True. gaps are the reason for electrical conductivity.Solution.pdfTrue. gaps are the reason for electrical conductivity.Solution.pdf
True. gaps are the reason for electrical conductivity.Solution.pdf
 
This is an example of a Lewis Acid. The CO2 acts like an acid becaus.pdf
This is an example of a Lewis Acid. The CO2 acts like an acid becaus.pdfThis is an example of a Lewis Acid. The CO2 acts like an acid becaus.pdf
This is an example of a Lewis Acid. The CO2 acts like an acid becaus.pdf
 
The Vestibular System, which is a contributed to our balance system .pdf
The Vestibular System, which is a contributed to our balance system .pdfThe Vestibular System, which is a contributed to our balance system .pdf
The Vestibular System, which is a contributed to our balance system .pdf
 
The inherent risk for an assertion about a derivative is its suscept.pdf
The inherent risk for an assertion about a derivative is its suscept.pdfThe inherent risk for an assertion about a derivative is its suscept.pdf
The inherent risk for an assertion about a derivative is its suscept.pdf
 
Solution I ) Average inventory = $610,000 5 = $122000Total Inven.pdf
Solution I ) Average inventory = $610,000  5 = $122000Total Inven.pdfSolution I ) Average inventory = $610,000  5 = $122000Total Inven.pdf
Solution I ) Average inventory = $610,000 5 = $122000Total Inven.pdf
 
1 D2 the decrease in entropy of the system is offset by an incr.pdf
1 D2  the decrease in entropy of the system is offset by an incr.pdf1 D2  the decrease in entropy of the system is offset by an incr.pdf
1 D2 the decrease in entropy of the system is offset by an incr.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
NaCl + H2OSolutionNaCl + H2O.pdf
NaCl + H2OSolutionNaCl + H2O.pdfNaCl + H2OSolutionNaCl + H2O.pdf
NaCl + H2OSolutionNaCl + H2O.pdf
 
Miller is US based investor and co-founder and current chairman of U.pdf
Miller is US based investor and co-founder and current chairman of U.pdfMiller is US based investor and co-founder and current chairman of U.pdf
Miller is US based investor and co-founder and current chairman of U.pdf
 
Marijuana plant belongs to the genus Cannabis. It is native to the C.pdf
Marijuana plant belongs to the genus Cannabis. It is native to the C.pdfMarijuana plant belongs to the genus Cannabis. It is native to the C.pdf
Marijuana plant belongs to the genus Cannabis. It is native to the C.pdf
 
InheritenceJava supports inheritance and thus, variables and metho.pdf
InheritenceJava supports inheritance and thus, variables and metho.pdfInheritenceJava supports inheritance and thus, variables and metho.pdf
InheritenceJava supports inheritance and thus, variables and metho.pdf
 
It is the temporal lobe of cerebrum. It is situated beneath the late.pdf
It is the temporal lobe of cerebrum. It is situated beneath the late.pdfIt is the temporal lobe of cerebrum. It is situated beneath the late.pdf
It is the temporal lobe of cerebrum. It is situated beneath the late.pdf
 
In cat,The ductus deferens also called the vas deferens leaves the t.pdf
In cat,The ductus deferens also called the vas deferens leaves the t.pdfIn cat,The ductus deferens also called the vas deferens leaves the t.pdf
In cat,The ductus deferens also called the vas deferens leaves the t.pdf
 
LeadCarbonate PbCO3 is ionic compound. electrostaticforces.pdf
  LeadCarbonate  PbCO3 is ionic compound. electrostaticforces.pdf  LeadCarbonate  PbCO3 is ionic compound. electrostaticforces.pdf
LeadCarbonate PbCO3 is ionic compound. electrostaticforces.pdf
 
Vo.pdf
   Vo.pdf   Vo.pdf
Vo.pdf
 
Lithium has 3 electrons. Since an s orbital only .pdf
                     Lithium has 3 electrons. Since an s orbital only .pdf                     Lithium has 3 electrons. Since an s orbital only .pdf
Lithium has 3 electrons. Since an s orbital only .pdf
 

Recently uploaded

DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 

Recently uploaded (20)

DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 

CipherDriver.javapackage Unit_6;import java.util.;public cl.pdf

  • 1. CipherDriver.java //package Unit_6; import java.util.*; public class CipherDriver { public static void main(String[] args) { int menu1, menu2; Scanner input = new Scanner(System.in); System.out.println("Enter (1) to encode a message"); System.out.println(" Enter (2) to decode a message"); System.out.println(" Enter (3) to exit"); menu1 = input.nextInt(); if (menu1 == 3){ System.exit(0); } if (menu1 == 1 ){ int n; System.out.println(" Enter (1) for substitution cipher"); System.out.println(" Enter (2) for shuffle cipher"); System.out.println(" Enter (3) to exit"); menu2 = input.nextInt(); System.out.print(" Enter text to be encoded: "); Scanner encodeText = new Scanner(System.in); String encode_text = encodeText.nextLine(); if (menu2 == 3) System.exit(0); if (menu2 == 1){ System.out.print(" Enter shift value: "); n = input.nextInt(); input.nextLine(); SubstitutionCipher sub = new SubstitutionCipher(n); String encodedMessage = sub.encode(encode_text);
  • 2. System.out.println("Encode Message: " + encodedMessage); } if (menu2 == 2){ System.out.print("Enter number of shuffles: "); n = input.nextInt(); input.nextLine(); ShuffleCipher shuffleCipher = new ShuffleCipher(n); String encodedText = shuffleCipher.encode(encode_text); System.out.println("Encode Message: " + encodedText); } encodeText.close(); } if (menu1 == 2){ int n; System.out.println(" Enter (1) for substitution cipher"); System.out.println(" Enter (2) for shuffle cipher"); System.out.println(" Enter (3) to exit"); menu2 = input.nextInt(); System.out.print("Enter text to be decode: "); Scanner decodeText = new Scanner(System.in); String decode_text = decodeText.nextLine(); if (menu2 == 3) System.exit(0); if (menu2 == 1){ System.out.print("Enter shift value: "); n = input.nextInt(); input.nextLine(); SubstitutionCipher substitution = new SubstitutionCipher(n); String decodedText = substitution.decode(decode_text); System.out.println("Decoded Message: " + decodedText); } if (menu2 == 2){ System.out.print("Enter number of shuffles: ");
  • 3. n = input.nextInt(); input.nextLine(); ShuffleCipher shuffleCipher = new ShuffleCipher(n); String decodedText = shuffleCipher.decode(decode_text); System.out.println("Decoded Message: " + decodedText); } decodeText.close(); } input.close(); } } ShuffleCipher.java //package Unit_6; // Create a class ShuffleCipher that implements the interface MessageEncoder public class ShuffleCipher implements MessageEncoder, MessageDecoder { // The constructor should have one parameter called n private int n; // The constructor which takes the shuffle value public ShuffleCipher (int n){ this.n = n; } // Performs single shuffle private String shuffle(String text){ int splitLetter; if (text.length() % 2 == 0) splitLetter = text.length() / 2; else splitLetter = ((text.length() + 1) / 2); String first = text.substring(0, splitLetter); String second = text.substring(splitLetter); String shuffleText = ""; for(int i = 0, j = 0; i < first.length(); i++, j++){ shuffleText += first.charAt(i); if(j < second.length())
  • 4. shuffleText += second.charAt(i); } return shuffleText; } // Decodes the shuffled message private String decodeShuffle(String text){ String firstHalf = "", secondHalf = ""; for(int i=0;i Solution CipherDriver.java //package Unit_6; import java.util.*; public class CipherDriver { public static void main(String[] args) { int menu1, menu2; Scanner input = new Scanner(System.in); System.out.println("Enter (1) to encode a message"); System.out.println(" Enter (2) to decode a message"); System.out.println(" Enter (3) to exit"); menu1 = input.nextInt(); if (menu1 == 3){ System.exit(0); } if (menu1 == 1 ){ int n; System.out.println(" Enter (1) for substitution cipher"); System.out.println(" Enter (2) for shuffle cipher"); System.out.println(" Enter (3) to exit"); menu2 = input.nextInt(); System.out.print(" Enter text to be encoded: "); Scanner encodeText = new Scanner(System.in); String encode_text = encodeText.nextLine();
  • 5. if (menu2 == 3) System.exit(0); if (menu2 == 1){ System.out.print(" Enter shift value: "); n = input.nextInt(); input.nextLine(); SubstitutionCipher sub = new SubstitutionCipher(n); String encodedMessage = sub.encode(encode_text); System.out.println("Encode Message: " + encodedMessage); } if (menu2 == 2){ System.out.print("Enter number of shuffles: "); n = input.nextInt(); input.nextLine(); ShuffleCipher shuffleCipher = new ShuffleCipher(n); String encodedText = shuffleCipher.encode(encode_text); System.out.println("Encode Message: " + encodedText); } encodeText.close(); } if (menu1 == 2){ int n; System.out.println(" Enter (1) for substitution cipher"); System.out.println(" Enter (2) for shuffle cipher"); System.out.println(" Enter (3) to exit"); menu2 = input.nextInt(); System.out.print("Enter text to be decode: "); Scanner decodeText = new Scanner(System.in); String decode_text = decodeText.nextLine(); if (menu2 == 3) System.exit(0); if (menu2 == 1){
  • 6. System.out.print("Enter shift value: "); n = input.nextInt(); input.nextLine(); SubstitutionCipher substitution = new SubstitutionCipher(n); String decodedText = substitution.decode(decode_text); System.out.println("Decoded Message: " + decodedText); } if (menu2 == 2){ System.out.print("Enter number of shuffles: "); n = input.nextInt(); input.nextLine(); ShuffleCipher shuffleCipher = new ShuffleCipher(n); String decodedText = shuffleCipher.decode(decode_text); System.out.println("Decoded Message: " + decodedText); } decodeText.close(); } input.close(); } } ShuffleCipher.java //package Unit_6; // Create a class ShuffleCipher that implements the interface MessageEncoder public class ShuffleCipher implements MessageEncoder, MessageDecoder { // The constructor should have one parameter called n private int n; // The constructor which takes the shuffle value public ShuffleCipher (int n){ this.n = n; } // Performs single shuffle private String shuffle(String text){ int splitLetter; if (text.length() % 2 == 0) splitLetter = text.length() / 2;
  • 7. else splitLetter = ((text.length() + 1) / 2); String first = text.substring(0, splitLetter); String second = text.substring(splitLetter); String shuffleText = ""; for(int i = 0, j = 0; i < first.length(); i++, j++){ shuffleText += first.charAt(i); if(j < second.length()) shuffleText += second.charAt(i); } return shuffleText; } // Decodes the shuffled message private String decodeShuffle(String text){ String firstHalf = "", secondHalf = ""; for(int i=0;i