Dr. Maha Shamseddine Project 1: Dynamic Array CS310 – Spring23
1
Project 1: Polyalphabetic Cipher
DUE: Sunday, _February 19 at 11:59 PM
Basic Procedures
You must:
• Fill out a readme.txt file with your information (goes in your user folder, example readme.txt provided).
• Have a style and pass the automatic style checker (see P0).
• Comment your code well in JavaDoc style AND pass the automatic JavaDoc checker (see P0).
• Have code that compiles with the command: javac *.java in your user directory
You may:
• Add additional methods and variables, however these methods must be private.
You may NOT:
• Make your program part of a package.
• Add additional public methods or variables
• Use any built in Java Collections Framework classes anywhere in your program (e.g. no ArrayList,
LinkedList, HashSet, etc.).
• Alter any method signatures defined in this document of the template code. Note: “throws” is part of the
method signature in Java, don’t add/remove these.
• Add any additional import statements (or use the “fully qualified name” to get around this requirement).
• Add any additional libraries/packages which require downloading from the internet.
Setup
• Download the project1.zip and unzip it. This will create a folder section-yourGMUUserName-p1;
• Rename the folder replacing section with the 001 or 005 based on the lecture section you are in;
• Rename the folder replacing yourGMUUserName with the first part of your GMU email address;
• After renaming, your folder should be named something like: 001-jsmith-p1.
• Complete the readme.txt file (an example file is included: exampleReadmeFile.txt)
Submission Instructions
• Make a backup copy of your user folder!
• Remove all test files, jar files, class files, etc.
• You should just submit your java files and your readme.txt
• Zip your user folder (not just the files) and name the zip section-username-p1.zip (no other type of
archive) following the same rules for section and username as described above.
o The submitted file should look something like this:
001-jsmith-p1.zip –> 001-jsmith-p1 –> JavaFile1.java
JavaFile2.java
• Submit to blackboard.
Grading Rubric
Due to the complexity of this assignment, an accompanying grading rubric pdf has been included with this
assignment. Please refer to this document for a complete explanation of the grading..
The Caesar Cipher is one of the oldest and simplest ciphers used for encryption. It is defined as a
form of substitution cipher, where each letter of the text which we need to encrypt is replaced by
another letter with a fixed number of positions down the alphabet. For example if the integer key
which represents the offset (which is the number of positions each character of the input text is to
be shifted down the alphabet) is selected to be 1 then, in your plain text an A will be replaced by
B, a B by C, and so on. This method is named after Julius Caesar, who apparently used it to
communicate with his generals in the battle fields. Figure 1 demonstrates Caesar cipher where
the key selected is 3:
This encoding is based on modular arithmetic which involve first converting the characters into
numbers (say from 0 to 25), according to the scheme, A = 0, B = 1, …, Z = 25 then encoding and
decoding of a character x using a key (offset) n can be mathematically described as:
In this project, you will do a variation on the Caesar Cipher more specifically a polyalphabetic
cipher where each letter in the plain text is going to be encoded into more than one letter based
on a random number generator. You will follow the following protocol for
encryption/decryption:
1. To encrypt, generate the set of keys which is a set of 5 cipher-alphabets which represent 5
alphabetic mappings as demonstrated in figure 2. (Will be set in keys array)
2. Then generate for each letter in the plain text, a different random number: int
randSelectAlpha (range between 0 and 4) and store in int[] selectAlpha.
X 0 |
G 1 |
S 2 |
R 3 |
U 4 |
V 5 |
W 6 |
X 7 |
Y 8 |
j 9 |
F 10 |
T 11 |
Z 12 |
B 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
A 0 |
B 1 |
C 2 |
D 3 |
E 4 |
F 5 |
G 6 |
H 7 |
I 8 |
J 9 |
K 10 |
L 11 |
M 12 |
N 13 |
O 14 |
P 15 |
Q 16 |
R 17 |
S 18 |
T 19 |
U 20 |
V 21 |
W 22 |
X 23 |
Y 24 |
Z 25 |
B 0 |
F 1 |
R 2 |
Q 3 |
T 4 |
W 5 |
U 6 |
O 7 |
P 8 |
I 9 |
E 10 |
S 11 |
Y 12 |
A 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
A 0 |
B 1 |
C 2 |
D 3 |
E 4 |
F 5 |
G 6 |
H 7 |
I 8 |
J 9 |
K 10 |
L 11 |
M 12 |
N 13 |
O 14 |
P 15 |
Q 16 |
R 17 |
S 18 |
T 19 |
U 20 |
V 21 |
W 22 |
X 23 |
Y 24 |
Z 25 |
. . . . . . . .
cipher
alphabet 0
. . . . . . . .
cipher
alphabet 4
.
.
.
.
Figure 2. Keys: cipher alphabets
3. selectAlpha[i] indicates the cipher alphabet chosen for encoding the
corresponding ith letter in the plain text. For example, if the selectAlpha[i] turned
out to be 4 then cipher alphabet 4 is selected for encryption. That is if the ith letter in the
plain text is A then using cipher alphabet 4, it is replaced by B in the output cipher text.
For each letter in the plain text you will generate a selectAlpha[i]which will
indicate which cipher alphabet is used for replacement (substitution) in the output cipher
text.
4. At this point, the cipher text is completed. The receiver will decrypt the cipher text by
using the int[] selectAlpha to find the corresponding cipher alphabets used for
each letter in the cipher. At the end of the decryption the original plain text is recovered.
5. Every decrypted text is inserted to a textArchive dynamic array.
The details for accomplishing this cipher is below:
Task 1: ThreeTenCipher.java
– Constructor ThreeTenCipher() that initializes the keys array,
the textArchive, the cipherText, the plaintext, and sets the
sizeStored to 0.
– static char [][] keys: stores the 5 cipher alphabets each of
26 characters length.
– static String cipherText: This is the cipher text to be
decrypted.
– static String plainText: This is the plain text to be
encrypted.
– char textArchive[]: a character array with initial capacity
of 100 that contains all decoded text blocks which are the
output of the decrypt method of the EncryptDecrypt class .
– int sizeStored: the size of the stored text in textArchive.
– void insertText (char[] newText): Adds a new text to the
textArchive and updates the sizeStored to accommodate the
inserted text. If textArchive is full, it will increase the
size to 1.5 the original size to accommodate the new text
inserted. This method should be O(n).
– boolean cleanArchivedText(int start, int size): removes all
the character data from start to size-1. It throws
NoTextException, if there is no data to remove. It should
shrink the size after deleting the corresponding character
data to the current capacity-size. You need to check that the
indices are valid or else throw an ArrayIndexOutOfBounds
exception. Returns true if successful. This method should be
O(n).
– getTextArchive(int start, int size) returns the characters of
textArchive from start to size-1
– int getStorageCapacity(): returns the maximum storage capacity
of textArchive.
– int getSize():returns the size of character data inserted in
the textArchive.
– boolean isEmpty():checks if the textArchive is empty.
– boolean isFull():checks if the textArchive is full.
– setCipherText(String)
– String getCipherText()
– setPlainText(String)
– String getPlainText()
– setKeys(char[][] keys, int size): in the ThreeTenCipher we set
the size of keys to be 5 of 26 length cipher alphabets.
Task 2: EncryptDecrypt.java
– int plainTextSize:this instance variable contains the size of
the plaintext in the ThreeTenCipher class.
– void setPlainTextSize ( int s) plainTextSize setter sets it
equal to the length of plainText from ThreeTenCipher class
– int[] selectAlpha:this integer array of size equal to
plainTextSize that contains the random numbers to be used by
the encrypt/decrypt methods as described in the project
details.
– encrypt():starts by randomly setting the selectAlpha array,
then access the plainText in the ThreeTenCipher and produces
and sets the cipherText in the ThreeTenCipher.
– String decrypt():uses the cipherText from the ThreeTenCipher
and the instance variable selectAlpha to decrypt the
cipherText and returns the resulting text. decrypt then
calls the archiveDecrypted to store the result in the
ThreeTenCipher testArchive instance variable.
Task 3: ThreeTenCipherTest.java
This class will not be submitted or graded. Its for you to test your work.