SlideShare a Scribd company logo
1 of 3
7.8.1: Modify the program so that the user can specify an encryption key.
Modify the following program so that the user can specify an encryption key other than 3 with a
-k option. For example:
java CaeserCipher -k15 input.txt output.txt
Note: the only part of the program that can be modified is where it says /* Your code goes here
*/
---------------------------------------------------------------------------------------------------------------------
-
CaesarCipher.java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
/**
This program encrypts a file using the Caesar cipher.
*/
public class CaesarCipher
{
public static void main(String[] args) throws FileNotFoundException
{
String[] my_args = new String[3];
Scanner console = new Scanner(System.in);
my_args[0] = console.next();
my_args[1] = console.next();
my_args[2] = console.next();
final int DEFAULT_KEY = 3;
int key = DEFAULT_KEY;
String inFile = "";
String outFile = "";
int files = 0; // Number of command line arguments that are files
for (int i = 0; i < my_args.length; i++)
{
String arg = my_args[i];
if (arg.charAt(0) == '-')
{
// It is a command line option
char option = arg.charAt(1);
if (option == 'd') { key = -key; }
else if (option == 'k')
{
/* Your code goes here */
}
else { usage(); return; }
}
else
{
// It is a file name
files++;
if (files == 1) { inFile = arg; }
else if (files == 2) { outFile = arg; }
}
}
if (files != 2) { usage(); return; }
Scanner in = new Scanner(new File(inFile));
in.useDelimiter(""); // Process individual characters
PrintWriter out = new PrintWriter(outFile);
while (in.hasNext())
{
char from = in.next().charAt(0);
char to = encrypt(from, key);
out.print(to);
}
in.close();
out.close();
}
/**
Encrypts upper- and lowercase characters by shifting them
according to a key.
@param ch the letter to be encrypted
@param key the encryption key
@return the encrypted letter
*/
public static char encrypt(char ch, int key)
{
int base = 0;
if ('A' <= ch && ch <= 'Z') { base = 'A'; }
else if ('a' <= ch && ch <= 'z') { base = 'a'; }
else { return ch; } // Not a letter
int offset = ch - base + key;
final int LETTERS = 26; // Number of letters in the Roman alphabet
if (offset >= LETTERS) { offset = offset - LETTERS; }
else if (offset < 0) { offset = offset + LETTERS; }
return (char) (base + offset);
}
/**
Prints a message describing proper usage.
*/
public static void usage()
{
System.out.println("Usage: java CaesarCipher [-kKEY] [-d] infile outfile");
}
}
infile1.txt
Veni, vidi, vici
infile2.txt
Experience is the teacher of all things
infile3.txt
Men freely believe that which they desire

More Related Content

Similar to 7-8-1- Modify the program so that the user can specify an encryption k (1).docx

Multithreaded sockets c++11
Multithreaded sockets c++11Multithreaded sockets c++11
Multithreaded sockets c++11Russell Childs
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 ReviewSperasoft
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxadampcarr67227
 
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.pdfarshiartpalace
 
Lab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docxLab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docxDIPESH30
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Vincenzo Iozzo
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaonyash production
 
Qtp Training Deepti 4 Of 4493
Qtp Training Deepti 4 Of 4493Qtp Training Deepti 4 Of 4493
Qtp Training Deepti 4 Of 4493Azhar Satti
 
Mobile Email Security
Mobile Email SecurityMobile Email Security
Mobile Email SecurityRahul Sihag
 
Tutorial - 16 : How to pass parameters from one script to another by CallScri...
Tutorial - 16 : How to pass parameters from one script to another by CallScri...Tutorial - 16 : How to pass parameters from one script to another by CallScri...
Tutorial - 16 : How to pass parameters from one script to another by CallScri...Yogindernath Gupta
 
#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.hSilvaGraf83
 
#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.hMoseStaton39
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfarmyshoes
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Yandex
 

Similar to 7-8-1- Modify the program so that the user can specify an encryption k (1).docx (20)

Multithreaded sockets c++11
Multithreaded sockets c++11Multithreaded sockets c++11
Multithreaded sockets c++11
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 Review
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docx
 
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
 
Lab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docxLab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docx
 
Gps c
Gps cGps c
Gps c
 
Base de-datos
Base de-datosBase de-datos
Base de-datos
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaon
 
Qtp Training Deepti 4 Of 4493
Qtp Training Deepti 4 Of 4493Qtp Training Deepti 4 Of 4493
Qtp Training Deepti 4 Of 4493
 
Qe Reference
Qe ReferenceQe Reference
Qe Reference
 
Mobile Email Security
Mobile Email SecurityMobile Email Security
Mobile Email Security
 
CGI.ppt
CGI.pptCGI.ppt
CGI.ppt
 
Tutorial - 16 : How to pass parameters from one script to another by CallScri...
Tutorial - 16 : How to pass parameters from one script to another by CallScri...Tutorial - 16 : How to pass parameters from one script to another by CallScri...
Tutorial - 16 : How to pass parameters from one script to another by CallScri...
 
#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h
 
#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h#include stdio.h#include systypes.h#include syssocket.h
#include stdio.h#include systypes.h#include syssocket.h
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdf
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Sockets and Socket-Buffer
Sockets and Socket-BufferSockets and Socket-Buffer
Sockets and Socket-Buffer
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
 

More from AlanQHOOliveru

8- This molecule is a(n) (Be specific) 9- This molecule is a( n) 10- T.docx
8- This molecule is a(n) (Be specific) 9- This molecule is a( n) 10- T.docx8- This molecule is a(n) (Be specific) 9- This molecule is a( n) 10- T.docx
8- This molecule is a(n) (Be specific) 9- This molecule is a( n) 10- T.docxAlanQHOOliveru
 
8- Shareholders have the right to attempt to influence the actions of.docx
8- Shareholders have the right to attempt to influence the actions of.docx8- Shareholders have the right to attempt to influence the actions of.docx
8- Shareholders have the right to attempt to influence the actions of.docxAlanQHOOliveru
 
8- Making a left and a right turn at the same time are- A- independent.docx
8- Making a left and a right turn at the same time are- A- independent.docx8- Making a left and a right turn at the same time are- A- independent.docx
8- Making a left and a right turn at the same time are- A- independent.docxAlanQHOOliveru
 
8- Consider how the heavy elements that make up planets like the earth.docx
8- Consider how the heavy elements that make up planets like the earth.docx8- Consider how the heavy elements that make up planets like the earth.docx
8- Consider how the heavy elements that make up planets like the earth.docxAlanQHOOliveru
 
8- Identify the Tracing A- Premature Atral Complex B- Premature Ventri.docx
8- Identify the Tracing A- Premature Atral Complex B- Premature Ventri.docx8- Identify the Tracing A- Premature Atral Complex B- Premature Ventri.docx
8- Identify the Tracing A- Premature Atral Complex B- Premature Ventri.docxAlanQHOOliveru
 
8- Explain in detail- how is P2P file distribution concept is used in.docx
8- Explain in detail- how is P2P file distribution concept is used in.docx8- Explain in detail- how is P2P file distribution concept is used in.docx
8- Explain in detail- how is P2P file distribution concept is used in.docxAlanQHOOliveru
 
8- Dr- Dolly teaches composition at a two year community college- He c.docx
8- Dr- Dolly teaches composition at a two year community college- He c.docx8- Dr- Dolly teaches composition at a two year community college- He c.docx
8- Dr- Dolly teaches composition at a two year community college- He c.docxAlanQHOOliveru
 
8- 25 Points- To satisfy this question- a- Create a file under the -tm.docx
8- 25 Points- To satisfy this question- a- Create a file under the -tm.docx8- 25 Points- To satisfy this question- a- Create a file under the -tm.docx
8- 25 Points- To satisfy this question- a- Create a file under the -tm.docxAlanQHOOliveru
 
8- (7 points)- Consider the following network that operates if and onl.docx
8- (7 points)- Consider the following network that operates if and onl.docx8- (7 points)- Consider the following network that operates if and onl.docx
8- (7 points)- Consider the following network that operates if and onl.docxAlanQHOOliveru
 
74 Igmeouss Rocks Vilmene rexis ane moks that have on wallind frum las.docx
74 Igmeouss Rocks Vilmene rexis ane moks that have on wallind frum las.docx74 Igmeouss Rocks Vilmene rexis ane moks that have on wallind frum las.docx
74 Igmeouss Rocks Vilmene rexis ane moks that have on wallind frum las.docxAlanQHOOliveru
 
76) A lot of N-50 products are produced with 4 known to be defective-.docx
76) A lot of N-50 products are produced with 4 known to be defective-.docx76) A lot of N-50 products are produced with 4 known to be defective-.docx
76) A lot of N-50 products are produced with 4 known to be defective-.docxAlanQHOOliveru
 
75- of Puerto Ricans who immigrated to the United States After the ear.docx
75- of Puerto Ricans who immigrated to the United States After the ear.docx75- of Puerto Ricans who immigrated to the United States After the ear.docx
75- of Puerto Ricans who immigrated to the United States After the ear.docxAlanQHOOliveru
 
7-Consider a regression model Yi-xi2+xii where the independent random.docx
7-Consider a regression model Yi-xi2+xii where the independent random.docx7-Consider a regression model Yi-xi2+xii where the independent random.docx
7-Consider a regression model Yi-xi2+xii where the independent random.docxAlanQHOOliveru
 
7-1 Discussion- WorldCom- What Happened- Communication and group dynam.docx
7-1 Discussion- WorldCom- What Happened- Communication and group dynam.docx7-1 Discussion- WorldCom- What Happened- Communication and group dynam.docx
7-1 Discussion- WorldCom- What Happened- Communication and group dynam.docxAlanQHOOliveru
 
7-) Some molecular data place the giant panda in the bear family (Ursi.docx
7-) Some molecular data place the giant panda in the bear family (Ursi.docx7-) Some molecular data place the giant panda in the bear family (Ursi.docx
7-) Some molecular data place the giant panda in the bear family (Ursi.docxAlanQHOOliveru
 
7- What is a digital dashboard- Why is a dashboard needed instead of j.docx
7- What is a digital dashboard- Why is a dashboard needed instead of j.docx7- What is a digital dashboard- Why is a dashboard needed instead of j.docx
7- What is a digital dashboard- Why is a dashboard needed instead of j.docxAlanQHOOliveru
 
7- What charparteristics differentiate the radius and 8- Indicate the.docx
7- What charparteristics differentiate the radius and 8- Indicate the.docx7- What charparteristics differentiate the radius and 8- Indicate the.docx
7- What charparteristics differentiate the radius and 8- Indicate the.docxAlanQHOOliveru
 
7- What are the similarities between these surface features- What does.docx
7- What are the similarities between these surface features- What does.docx7- What are the similarities between these surface features- What does.docx
7- What are the similarities between these surface features- What does.docxAlanQHOOliveru
 
7- Use the data in the table below to calculate the mean difference- D.docx
7- Use the data in the table below to calculate the mean difference- D.docx7- Use the data in the table below to calculate the mean difference- D.docx
7- Use the data in the table below to calculate the mean difference- D.docxAlanQHOOliveru
 
7- The image below shows profiles of three couples (A-B and C) as well.docx
7- The image below shows profiles of three couples (A-B and C) as well.docx7- The image below shows profiles of three couples (A-B and C) as well.docx
7- The image below shows profiles of three couples (A-B and C) as well.docxAlanQHOOliveru
 

More from AlanQHOOliveru (20)

8- This molecule is a(n) (Be specific) 9- This molecule is a( n) 10- T.docx
8- This molecule is a(n) (Be specific) 9- This molecule is a( n) 10- T.docx8- This molecule is a(n) (Be specific) 9- This molecule is a( n) 10- T.docx
8- This molecule is a(n) (Be specific) 9- This molecule is a( n) 10- T.docx
 
8- Shareholders have the right to attempt to influence the actions of.docx
8- Shareholders have the right to attempt to influence the actions of.docx8- Shareholders have the right to attempt to influence the actions of.docx
8- Shareholders have the right to attempt to influence the actions of.docx
 
8- Making a left and a right turn at the same time are- A- independent.docx
8- Making a left and a right turn at the same time are- A- independent.docx8- Making a left and a right turn at the same time are- A- independent.docx
8- Making a left and a right turn at the same time are- A- independent.docx
 
8- Consider how the heavy elements that make up planets like the earth.docx
8- Consider how the heavy elements that make up planets like the earth.docx8- Consider how the heavy elements that make up planets like the earth.docx
8- Consider how the heavy elements that make up planets like the earth.docx
 
8- Identify the Tracing A- Premature Atral Complex B- Premature Ventri.docx
8- Identify the Tracing A- Premature Atral Complex B- Premature Ventri.docx8- Identify the Tracing A- Premature Atral Complex B- Premature Ventri.docx
8- Identify the Tracing A- Premature Atral Complex B- Premature Ventri.docx
 
8- Explain in detail- how is P2P file distribution concept is used in.docx
8- Explain in detail- how is P2P file distribution concept is used in.docx8- Explain in detail- how is P2P file distribution concept is used in.docx
8- Explain in detail- how is P2P file distribution concept is used in.docx
 
8- Dr- Dolly teaches composition at a two year community college- He c.docx
8- Dr- Dolly teaches composition at a two year community college- He c.docx8- Dr- Dolly teaches composition at a two year community college- He c.docx
8- Dr- Dolly teaches composition at a two year community college- He c.docx
 
8- 25 Points- To satisfy this question- a- Create a file under the -tm.docx
8- 25 Points- To satisfy this question- a- Create a file under the -tm.docx8- 25 Points- To satisfy this question- a- Create a file under the -tm.docx
8- 25 Points- To satisfy this question- a- Create a file under the -tm.docx
 
8- (7 points)- Consider the following network that operates if and onl.docx
8- (7 points)- Consider the following network that operates if and onl.docx8- (7 points)- Consider the following network that operates if and onl.docx
8- (7 points)- Consider the following network that operates if and onl.docx
 
74 Igmeouss Rocks Vilmene rexis ane moks that have on wallind frum las.docx
74 Igmeouss Rocks Vilmene rexis ane moks that have on wallind frum las.docx74 Igmeouss Rocks Vilmene rexis ane moks that have on wallind frum las.docx
74 Igmeouss Rocks Vilmene rexis ane moks that have on wallind frum las.docx
 
76) A lot of N-50 products are produced with 4 known to be defective-.docx
76) A lot of N-50 products are produced with 4 known to be defective-.docx76) A lot of N-50 products are produced with 4 known to be defective-.docx
76) A lot of N-50 products are produced with 4 known to be defective-.docx
 
75- of Puerto Ricans who immigrated to the United States After the ear.docx
75- of Puerto Ricans who immigrated to the United States After the ear.docx75- of Puerto Ricans who immigrated to the United States After the ear.docx
75- of Puerto Ricans who immigrated to the United States After the ear.docx
 
7-Consider a regression model Yi-xi2+xii where the independent random.docx
7-Consider a regression model Yi-xi2+xii where the independent random.docx7-Consider a regression model Yi-xi2+xii where the independent random.docx
7-Consider a regression model Yi-xi2+xii where the independent random.docx
 
7-1 Discussion- WorldCom- What Happened- Communication and group dynam.docx
7-1 Discussion- WorldCom- What Happened- Communication and group dynam.docx7-1 Discussion- WorldCom- What Happened- Communication and group dynam.docx
7-1 Discussion- WorldCom- What Happened- Communication and group dynam.docx
 
7-) Some molecular data place the giant panda in the bear family (Ursi.docx
7-) Some molecular data place the giant panda in the bear family (Ursi.docx7-) Some molecular data place the giant panda in the bear family (Ursi.docx
7-) Some molecular data place the giant panda in the bear family (Ursi.docx
 
7- What is a digital dashboard- Why is a dashboard needed instead of j.docx
7- What is a digital dashboard- Why is a dashboard needed instead of j.docx7- What is a digital dashboard- Why is a dashboard needed instead of j.docx
7- What is a digital dashboard- Why is a dashboard needed instead of j.docx
 
7- What charparteristics differentiate the radius and 8- Indicate the.docx
7- What charparteristics differentiate the radius and 8- Indicate the.docx7- What charparteristics differentiate the radius and 8- Indicate the.docx
7- What charparteristics differentiate the radius and 8- Indicate the.docx
 
7- What are the similarities between these surface features- What does.docx
7- What are the similarities between these surface features- What does.docx7- What are the similarities between these surface features- What does.docx
7- What are the similarities between these surface features- What does.docx
 
7- Use the data in the table below to calculate the mean difference- D.docx
7- Use the data in the table below to calculate the mean difference- D.docx7- Use the data in the table below to calculate the mean difference- D.docx
7- Use the data in the table below to calculate the mean difference- D.docx
 
7- The image below shows profiles of three couples (A-B and C) as well.docx
7- The image below shows profiles of three couples (A-B and C) as well.docx7- The image below shows profiles of three couples (A-B and C) as well.docx
7- The image below shows profiles of three couples (A-B and C) as well.docx
 

Recently uploaded

How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 

Recently uploaded (20)

How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 

7-8-1- Modify the program so that the user can specify an encryption k (1).docx

  • 1. 7.8.1: Modify the program so that the user can specify an encryption key. Modify the following program so that the user can specify an encryption key other than 3 with a -k option. For example: java CaeserCipher -k15 input.txt output.txt Note: the only part of the program that can be modified is where it says /* Your code goes here */ --------------------------------------------------------------------------------------------------------------------- - CaesarCipher.java import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program encrypts a file using the Caesar cipher. */ public class CaesarCipher { public static void main(String[] args) throws FileNotFoundException { String[] my_args = new String[3]; Scanner console = new Scanner(System.in); my_args[0] = console.next(); my_args[1] = console.next(); my_args[2] = console.next(); final int DEFAULT_KEY = 3; int key = DEFAULT_KEY; String inFile = ""; String outFile = ""; int files = 0; // Number of command line arguments that are files for (int i = 0; i < my_args.length; i++) { String arg = my_args[i]; if (arg.charAt(0) == '-') { // It is a command line option
  • 2. char option = arg.charAt(1); if (option == 'd') { key = -key; } else if (option == 'k') { /* Your code goes here */ } else { usage(); return; } } else { // It is a file name files++; if (files == 1) { inFile = arg; } else if (files == 2) { outFile = arg; } } } if (files != 2) { usage(); return; } Scanner in = new Scanner(new File(inFile)); in.useDelimiter(""); // Process individual characters PrintWriter out = new PrintWriter(outFile); while (in.hasNext()) { char from = in.next().charAt(0); char to = encrypt(from, key); out.print(to); } in.close(); out.close(); } /** Encrypts upper- and lowercase characters by shifting them according to a key. @param ch the letter to be encrypted @param key the encryption key @return the encrypted letter */ public static char encrypt(char ch, int key) { int base = 0; if ('A' <= ch && ch <= 'Z') { base = 'A'; } else if ('a' <= ch && ch <= 'z') { base = 'a'; } else { return ch; } // Not a letter int offset = ch - base + key;
  • 3. final int LETTERS = 26; // Number of letters in the Roman alphabet if (offset >= LETTERS) { offset = offset - LETTERS; } else if (offset < 0) { offset = offset + LETTERS; } return (char) (base + offset); } /** Prints a message describing proper usage. */ public static void usage() { System.out.println("Usage: java CaesarCipher [-kKEY] [-d] infile outfile"); } } infile1.txt Veni, vidi, vici infile2.txt Experience is the teacher of all things infile3.txt Men freely believe that which they desire