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

PDF
The java program that prompts user to enter a string and .pdf
PDF
Network security
PDF
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
PDF
Cryptography and network security record for cse .pdf
PDF
Develop an encryption and decryption algorithm Your program should a.pdf
DOCX
encryptFile- java import java-io-IOException- import java-nio-file-Fil.docx
DOCX
import java-io-IOException- import java-nio-file-Files- import java-ni.docx
PDF
IT6712 lab manual
The java program that prompts user to enter a string and .pdf
Network security
IT8761-SECURITY LABORATORY-590519304-IT8761 security labmanual.pdf
Cryptography and network security record for cse .pdf
Develop an encryption and decryption algorithm Your program should a.pdf
encryptFile- java import java-io-IOException- import java-nio-file-Fil.docx
import java-io-IOException- import java-nio-file-Files- import java-ni.docx
IT6712 lab manual

More from ravikapoorindia (20)

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

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PPTX
Lesson notes of climatology university.
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PPTX
Institutional Correction lecture only . . .
PDF
Insiders guide to clinical Medicine.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
master seminar digital applications in india
PDF
RMMM.pdf make it easy to upload and study
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Classroom Observation Tools for Teachers
Lesson notes of climatology university.
PPH.pptx obstetrics and gynecology in nursing
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Supply Chain Operations Speaking Notes -ICLT Program
Cell Types and Its function , kingdom of life
Institutional Correction lecture only . . .
Insiders guide to clinical Medicine.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Basic Mud Logging Guide for educational purpose
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
VCE English Exam - Section C Student Revision Booklet
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
01-Introduction-to-Information-Management.pdf
master seminar digital applications in india
RMMM.pdf make it easy to upload and study
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Ad

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