Lab 11, Esc101, 2004-05 Semester-II
Solve the following problems
Problem 1
Write a program that asks the user for a file name and that prints
the number of lines in that file. The program wc can be used to count the
number of lines in a file. For instance, wc -l Test.java, will
give the number of lines in the file Test.java
Problem 2
Write a program Find that
searches all files specified on the command line and prints out all
lines containing a keyword. For example, if you call
java Find Buff report.txt address.txt
Homework.java
then the program might print
report.txt: Buffer style lunch
will be available at the
address.txt: Buffet,
Warren|11801 Trenton Court| Dallas|TX
address.txt: Walters, Winnie| 59
Timothy Circle| Buffalo|MI
Homework.java: BufferedReader in;
The keyword is always the first command line argument.
Extra Credit
Problem 3 Playfair
cipher
In this you have to encrypt and decrypt a file. Encryption is
done with pairs of letters
together. You pick a keyword and remove duplicate letters from it. Then
you fill the keyword, and the remaining letters of the alphabet, into
a 5 X 5 square. (Since there are only 25 squares, I and J
are considered the same letter.) Here is such an arrangement with
the keyword PLAYFAIR:
P L A Y F
I R B C D
E G H K M
N O Q S T
U V W X Z
To encrypt a letter pair, say AT, look at the rectangle with corners A
and T: The encoding of this pair is formed by looking at the other
two corners of the rectangle-- in this case, FQ. If both letters happen
to be in the same row or column, such as GO, simply swap the two
letters. Decryption is done in the same way.
Write a program which encrypts a given file and
writes to a second file. For example, java Encrypt test.txt playfair enc.txt
should encrypt the contents of the file test.txt
and write onto file enc.txt
using the keyword "playfair".
Also write a similar program Decrypt
to decrypt a given file and write onto another file.