psptnum"
| file vault0 | sample run |
user joe shift+vigenere ?5d`54=22d5Boqqv user ann shift+caesar 2018^midGO_NAVY_ data joe vigenere LjTmZ8o*s=CEWyi.q data joe caesar z53y5vJKDIHDHO data ann caesar instrument_french_horn |
~/$ java Vault vault0 username: joe password: ← password not echoed to the screen! Access granted! > labels ssnum combo > get ssnum 892-88-1263 > quit |
The project has three main pieces: encryption algortihms, hash algorithms, and the vault. If you do a good job of following OOP best-practices in producing your solutions to the first two parts, you should be OK on the third. Otherwise ...
*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyzI've carefully chosen encryption and hashing algrithms that produce results that are in that restricted character set as well. Any encrypted entry in a vault-file and any user-entered label, data or password that is outside of these bounds is an error and should result in some kind of message.
String objects, other times as objects of
type char[]. Just in case you didn't know
here's how to convert back and forth:
String str = "foo"; char[] buff = str.toCharArray(); // convert String to char[] String rts = new String(buff); // convert char[] to String
clear,
caesar, and
vigenere (all described later).
A Part 1 solution will be a program TestEncryptors that allows
the user to encrypt a test message of their choice using any one
of the three algorithms above. The program itself is not the
important product here: correct implmentations of the three
encryption algorithms with a single coherent interface and a
well-thought out system of error-handling is the real point.
| example 1 | example 2 | example 3 |
~/$ java TestEncryptors algorithm: clear password : grumpy message : This_is_just_test:1234 plain : This_is_just_test:1234 cipher: This_is_just_test:1234 decryp: This_is_just_test:1234 |
~/$ java TestEncryptors algorithm: caesar password : grumpy message : This_is_just_test:1234 plain : This_is_just_test:1234 cipher: y<=G3=G3>IGH3H9GH_VWXY decryp: This_is_just_test:1234 |
~/$ java TestEncryptors algorithm: vigenere password : grumpy message : This_is_just_test:1234 plain : This_is_just_test:1234 cipher: @_ceTg_VdghrKk_ei8nz-w decryp: This_is_just_test:1234 |
Your project will benefit tremendously from following good object oriented design principals. To help you out, I'm going to impose more structure on this first part of the assignment. Here are the rules and recommendations:
ArrayList< >
is all about. Fear not, it will be covered in the very
next class. For now, just know this: It's just like an
array except a) it has an add( ) method to
add new elements to the back, and b) you access element
the ith element
not with "[i]", but with the ".get(i)".
| Encryptor.java | TestEncryptors.java |
| Clear.java | |
caesar): see
Caesar-shift details.
vigenere): see
Vigenere details.
algorithm password plaintext ciphertext note clear whale65] 987:test;DOG 987:test;DOG caesar whale65] 987:test;DOG ?>=@zkyzAJUM vigenere whale65] 987:test;DOG 5vn+^q-V7158 clear 10$More 987:test;DOG error $ not allowed in key caesar 10$More 987:test;DOG error $ not allowed in key vigenere 10$More 987:test;DOG error $ not allowed in key clear hone_5^ 1$L0VE$cats$ error $ not allowed in plaintext caesar hone_5^ 1$L0VE$cats$ error $ not allowed in plaintext vigenere hone_5^ 1$L0VE$cats$ error $ not allowed in plaintextImportant! When there's an error, do not print any error messages. Your program should crash with some kind of uncaught exception!
A Part 2 solution is a program TestHashers that
allows the user to hash a test message (which will the "password") of their choice using
one of the following three algorithms:
padcut,
shift+caesar, and
shift+vigenere.
The program itself is not the important product here: correct
implmentations of the three hashing algorithms with a
single coherent interface and a well-thought out system of
error-handling is the real point.
Note: Please take note of the nice design we
laid out for you for the encryption stuff in Part 1, and try
to do something similar here!
Gotcha! If you have char[] foo
and you want to print it out like a string, you should convert
it first, like this:
System.out.println("foo = " + (new String(foo)))
| example 1 | example 2 | example 3 | example 4 |
~/$ java TestHashers algorithm: padcut password : grumpy password read : grumpy hash computed : grumpyxxxxxxxxxx | ~/$ java TestHashers algorithm: padcut password : 0123456789abcdefuvw password read : 0123456789abcdefuvw hash computed : 0123456789abcdef |
~/$ java TestHashers algorithm: shift+caesar password : grumpy password read : grumpy hash computed : hxgZorxKIJQw51,` |
~/$ java TestHashers algorithm: shift+vigenere password : grumpy password read : grumpy hash computed : U@P9yh>l0N<;_o]o |
padcut algorithm is to have the hash of the
message/password be the the first 16 characters of message
itself, if the message/password is at least 16 characters long, or
the message/password with x's added to the back
in order to pad out to 16 characters if the
message is shorter.shift+
algorithm adapts a symmetric encryption algorithm to produce
a hash, which gives us
shift+caesar and shift+vigenere
(you could offer shift+clear if you wanted to):
see shift+ details.
algorithm password hash note padcut whale65] whale65]xxxxxxxx shift+caesar whale65] V^n]PehnA?@Gm+xs shift+vigenere whale65] C+HK`8fzqA+4P3Q[ padcut 10$more error $ not allowed in key shift+caesar 10$more error $ not allowed in key shift+vigenere 10$more error $ not allowed in keyImportant! When there's an error, do not print any error messages. Your program should crash with some kind of uncaught exception!
quit, which immediately quits the
program.
Important! Please use System.console to read
both the username and password, as in the TextEncryptors
example.
| file vault3 | example 1a, 1b | example 2a, 2b | example 3a, 3b |
user aviv padcut princessxxxxxxxx user mcdowell shift+caesar FDELr0,x[csbUjms user brown shift+vigenere 7sM7;9/D:@R_c]3i |
~/$ java Vault vault3 username: aviv password: 123456 Access denied! ~/$ java Vault vault3 username: aviv password: princess Access granted! > quit |
~/$ java Vault vault3 username: mcdowell password: StandDesk Access denied! ~/$ java Vault vault3 username: mcdowell password: Cuddly1 Access granted! > quit |
~/$ java Vault vault3 username: brown password: G0N4\/y Access denied! ~/$ java Vault vault3 username: brown password: OOP-C-day-Z Access granted! > quit |
java Vault
<filename>, and it's prompts and output
messages must match the format of the examples above
exactly. This also means that the password should not be
echoed to the screen. See TestEncryptors.java for an example
of how to do this.
stdout). Here is a list of some possible errors and the
required output/behavior:
usage: java Vault [-au] <filename>"
and exit. (The "[-au]" will make sense in the next part.)
Error! File 'name' could not be opened."
and exit.
Error! File 'name' improperly formatted."
and exit. (see vault3.1 for example)
Note: this message comes before either the username
or the password are read.
Access denied!" is the proper
message for this case.
Note: this message always comes after
both the username and the password are read.
Error! Hash algorithm 'hashalg' not supported."
and exit. (see vault3.2 and login
with username=aviv and password=princess for example)
Note: this message always comes after
both the username and the password are read.
java Vault -au filenamewhere the -au option indicates that you want to add a user. The user is prompted to enter username, password and a hash algorithm as shown in the examples below.
| 1. file vault4 | 2. add user | 3. new file vault4 | 4. authenticate |
user aviv padcut princessxxxxxxxx |
~/$ java Vault -au vault4 username: roche password: Tuba+Time Hash algorithm: shift+caesar |
user aviv padcut princessxxxxxxxx user roche shift+caesar *0TRSZ/>:5iq0pcx |
~/$ java Vault vault4 username: roche password: Tuba+Time Access granted! > quit |
Note: The new version of the file should contain all the original users, in the original order, with the new user added to the end.
PrintWriter pw = null;
try {
pw = new PrintWriter(new File(fname));
}
catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
}
// Do whatever you need to do, e.g. pw.println("foo")
if (pw != null) pw.close();
Error! Invalid symbol 'x' in password."
and exit.
Note: this message only comes after
the username, password and algorithm have all been read.
Error! Hash algorithm 'hashalg' not supported."
and exit.
Note: this message only comes after
the username, password and algorithm have all been read.
Error! Username 'username' already in use."
and exit.
Note: this message only comes after
the username, password and algorithm have all been read.
Note: Writing to files is a bit new. See the annotation to the right for details. PrintWriter objects give you your usual print, println and printf. When a new user is added, you completely overwrite the vaultfile. That means you have to write entries for all the existing users as well as for the new user.
data username encalg cipertextwhere encalg can be one of
clear,
caesar, or
vigenere, and ciphertext is a
ciphertext-string that decrypts (with the user's password as
key and using encryption algorithm encalg)
to a plaintext string of the form label_text,
where both the label and the text come from the ASCII range
42-122, but the label does not include the '_' character.
For example, suppose there is a user crabbe with password
FlappyBirds. We might have a data entry like this:
data crabbe caesar ,//=0>>*j@8-0=*P*c=48,@7/*l7J
Note: decrypt with caesar and password FlappyBirds gives: address_Number_4_Grimauld_Pl.
\_____/ \___________________/
label text
This means that the entry represents the label "address"
with the associated text "Number_4_Grimauld_Pl.".
| file vault5a | sample run 1 | file vault5b | sample run 2 |
user aviv padcut princessxxxxxxxx data aviv clear weakness_backhand data aviv caesar bZa`WQwtspu+vpyyxx data aviv vigenere [XdX*Kf\TF\XG.ajZZb\WX |
~/$ java Vault vault5a username: aviv password: princess Access granted! > labels weakness phone faveBand > get weakness backhand > get faveBand One_Direction > quit |
user aviv shift+caesar /+wZbraTilrECDKq user mcdowell shift+vigenere fW*XrW]7P_uMnoAZ data aviv vigenere [XdX*Kf\TF\XG.ajZZb\WX data mcdowell caesar HGCTAvQWNTQRJQDKC data aviv caesar bZa`WQwtspu+vpyyxx |
$ java Vault vault5b username: mcdowell password: StandDesk Access granted! > labels fear > get fear Coulrophobia > get faveBand > done Unknown command 'done'. > quit |
Unknown command 'comm'."
and continue reading more commands.
Error! Encryption algorithm
'encalg' not supported.", or
Error! corrupted entry 'ciphertext' in vault file.".
add encalg label textThis command should add a data entry for the current user, with the encryption algorithm given by encalg, and form the ciphertext by encryption label
_text
with algorithm encalg using the password the user
authenticated with as the key for the encryption.
| file vault6a before | sample run | file vault6a after |
user aviv padcut princessxxxxxxxx user roche shift+caesar *0TRSZ/>:5iq0pcx data roche caesar dgn]WZac]Wja\af_ |
$ java Vault vault6a username: roche password: Tuba+Time Access granted! > add vigenere ssnum 123-45-6789 > quit |
user aviv padcut princessxxxxxxxx user roche shift+caesar *0TRSZ/>:5iq0pcx data roche caesar dgn]WZac]Wja\af_ data roche vigenere LmU[n8punW.md7aw+ |
Error! Encryption algorithm 'encalg' not supported.",
print the prompt and await the next command from the user.
Error! Label 'label' is invalid.",
print the prompt and await the next command from the user.
Error! Invalid character 'X' in text.",
print the prompt and await the next command from the user.
~/$ java TestHashers algorithm: shift+vigenere password : ThisIsExactly_16 password read : ThisIsExactly_16 hash computed : 4rgZDs.8u1bjr5A/ |
~/$ java TestHashers algorithm: shift+vigenere password : ThisIsExactly_16_plus_some password read : ThisIsExactly_16_plus_some hash computed : K>0F_<6vvHfYP:c^ |
README
with your name and alpha code, which step you are submitting
for (including any extra credit), and any issues you know your program has.
submit -c=IC211 -p=proj02 *.java README