Requirements: Choose ONE of the following projects and follow all of the directions in this project
specification for that project. You will be in a team with people who chose the other projects.
This Final Project has a Presentation Requirement that must be given during the scheduled time of the Final
Exam, on Monday December 15th from 10:00AM - 11:30 AM. You must attend and give the presentation
portion, or that part of your grade will be zero. The presentation will be on one of the projects you did not
choose to implement yourself, but one of your teammates did.
Project Option 1: The Beale Cipher
In the 1820s, Thomas Jefferson Beale created a cipher to hide the location of his family's fortune. He encoded
three documents with his cipher. The first document was the location of the treasure. The second was a
description of contents of the treasure. The third was a list of heirs and their next of kin. The second
document has been decoded, but the other two have not, to this day. The treasure is estimated to be worth
$63 million in today's dollars.
The documents all appear as lists of numbers. The second document was decoded using the Declaration of
Independence as a key. Each word in the Declaration was numbered, and each number in the cipher
corresponds to the first letter of the word in the Declaration. Here is a very simple example:
Message: Curse your sudden but inevitable betrayal
Document: "It was the year of fire... the year of destruction... the year we took back what was ours... It was
the year of rebirth... the year of great sadness... the year of pain... and the year of joy. It was a new age. It was
the end of history. It was the year everything changed."
Document Key: "It(1) was(2) the(3) year(4) of(5) fire(6)... the(7) year(8) of(9) destruction(10)... the(11)
year(12) we(13) took(14) back(15) what(16) was(17) ours(18)... It(19) was(20) the(21) year(22) of(23)
rebirth(24)... the(25) year(26) of(27) great(28) sadness(29)... the(30) year(31) of(32) pain(33)... and(34) the(35)
year(36) of(37) joy(38). It(39) was(40) a(41) new(42) age(43). It(44) was(45) the(46) end(47) of(48) history(49).
It(50) was(51) the(52) year(53) everything(54) changed(55)."
Encoded Message: 55 0 24 29 47 53 18 0 24 29 0 10 10 47 42 15 0 30 19 42 54 0 1 46 43 15 0 47 15 47 25 24
41 4 43 0
55 0 24 29 47 53 18 0 24 29 0 10 10 47 42 15 0 30 19 42 54 0 1 46 43
C U R S E Y O U R S U D D E N B U T I N E V I T A
15 0 47 15 47 25 24 41 4 43 0
B L E B E T R A Y A L
Things to notice:
1. If there is a letter/character in the Message that is not in the Key, the number returned should be zero
2. If there is a letter in the Message that is in the Key more than once, choose one location at random
3. You do not have to output spaces
4. Upper and lower case letters are equal. Run toUpperCase on your strings before processing.
5. Words will not start with punctuation, numbers, or weird things.
This story is likely a hoax, but the cipher is real and it's a surprisingly effective cipher. Write your code in
Beale.java and you must include the following methods:
// Use a document sent through an input Stream
// (such as System.in or a file)
// The first letter of each word will correspond to the number
// of that word in the document
public void encodeDocument(InputStream is)
// Use a document that is inside a single string
public void encodeDocument(String s)
// Encode the String s and return an array of integers
public int[] encodeMessage(String s)
// Given an array of integers, decode it into a string
public String decodeMessage(int[] a)
// Print the contents of the cipher, ten letters per line, with
// spaces in between the letters
public void dump()
// Print the contents of an int array, ten numbers per line, with
// spaces in between the numbers.
public void dump(int[] a)
Hints:
• Test your code with a document that has a word starting with every letter of the alphabet
• Test your code with a document that does not have a word starting with every letter of the alphabet.
Further Research:
http://www.atariage.com/magazines/magazine_page.html?MagazineID=2&CurrentPage=10
http://www.atariage.com/magazines/magazine_page.html?MagazineID=2&CurrentPage=11
http://en.wikipedia.org/wiki/Beale_ciphers
http://www.unmuseum.org/bealepap.htm
Example Output: Beale.java
if a file barbie.txt contains:
At breakfast one morning, Barbie is already hard at work on her laptop.
What are you doing? asks Skipper. Playing The Sims? Reading Facebook? Nope,
I’m creating a new game, explains Barbie. For kids, since it’s so important
to get them interested in computer science early especially girls! Not that
there’s anything wrong with The Sims or Facebook, Skipper, but you know,
you could create your own game or social network someday! Hey, your game
has robot puppies! says Skipper, looking over her shoulder at the art.
Robots are sweet! Can I play it? Well, it’s not quite done yet, Barbie
says, smiling. Really good games are made by a team of people. I’m doing
some of the coding now, but Stephen and Brian are helping, too. There are
lots of pieces to making a game, like art and music and storyline. Brian
drew that puppy. You’re a good artist, Skipper. Maybe you could be a
graphic designer when you grow up. Skipper grins. I love art, but I really
love science, too. Physics is my favorite class. I think I want to be a
physicist.
Then, after running beale < barbie.txt
b.encodeDocument(System.in);
b.dump();
produces the following output:
A B O M B I A H A W
O H L W A Y D A S P
T S R F N I C A N G
E B F K S I S I T G
T I I C S E E G N T
T A W W T S O F S B
Y K Y C C Y O G O S
N S H Y G H R P S S
L O H S A T A R A S
C I P I W I N Q D Y
B S S R G G A M B A
T O P I D S O T C N
B S A B A H T T A L
O P T M A G L A A M
A S B D T P Y A G A
S M Y C B A G D W Y
G U S G I L A B I R
L S T P I M F C I T
I W T B A P
int[] codex = b.encodeMessage("Your taste buds cannot repel swag of this
magnitude.");
b.dump(codex);
produces the following output:
65 116 161 22 20 140 78 20 46 167
161 114 101 43 128 24 48 56 50 169
30 173 46 12 162 9 138 148 116 32
49 82 42 141 3 109 163 28 95 117
161 114 30 0
System.out.println(b.decodeMessage(codex));
produces the following output:
YOURTASTEBUDSCANNOTREPELSWAGOFTHISMAGNITUDEA