Professional Documents
Culture Documents
Lab - 8
Lab Practice Questions
Encryption and Decryption
1) Write a Java program to implement “Caesar Cipher”.
This is a method to encrypt a given text and decrypt the
‘encrypted’ text. Please read information on ‘Caesar
cipher’ at wikipedia.org.
– Example:
Encryption: Key -3, For the input string
“Welcome to the lab” encrypted text is
“zhofrph wr wkh oae”
try{
Scanner s = new Scanner(myfile);
while(s.hasNextLine())
{
String data = s.nextLine();
System.out.println(data);
}
}catch(FileNotFoundException e){ System.out.println("No file specified is found");}
}
}
Write to a File
public class Main
{
try {
Scanner s = new Scanner(myfile);
FileWriter f = new FileWriter(myfile);
System.out.println("I am trying to write");
f.write("hello csc 185");
f.close();
System.out.println("Wrote!");