BBM 103: Introduction to Programming Laboratory I Programming Assignment 3




5/5 - (2 votes)

An expedition of an alien race called Binarians from planet Xenu, which is located in Vela
constellation, has recently wound up in our Solar system. Their civilization is dedicated to
establishing peace and justice throughout the universe. However, Binarians are not the most
patient race in the universe: if they deem a species too violent, they simply annihilate it.
Binarian spaceship dropped out of warp near Saturn earlier this year, and is expected to approach
the Earth in a couple of days. In the meantime, they have studied the Earth and human race,
and come to a conclusion that we are greedy savages who kill each other, wage absurd wars, and
let many people starve and live in inhuman conditions even though there are enough resources
on our planet for everyone.
Nevertheless, they decided to give us one last chance to avoid annihilation of our race if we can
prove that we are actually intelligent and worthy of life in this universe. Our satellites intercepted
the transmissions of their encrypted messages, and a team of world’s top cryptologists, linguists,
and computer scientists was assembled in secluded, top-secret facilities to work on deciphering
those messages.
However, someone managed to sabotage the mission and we lost all contact with the team just
as they were on the verge of a breakthrough. Luckily, there was a backup plan that the saboteur
didn’t know about: one team member was secretly uploading their findings with each progress to
a secure cloud. We may not be able to establish contact with the team in time to save the Earth,
so it is now up to you, the students of Hacettepe University Computer Engineering Department,
to complete the mission and save our planet and the whole human race from extinction.
Fall 2016
BBM 103: Introduction to Programming Laboratory I Programming Assignment 3
1. Mission: Decrypt Alien Message (30 pts)
The original Binarian message consists of characters and
symbols unknown to humans, but the linguists assigned
ASCII characters to each symbol to simplify the process
of language decryption. They managed to extrapolate
the meaning of the words included in the message, and
compile a Binarian-English Dictionary. The compiled
dictionary is stored in dictionary.txt which you are
supposed to import into your program (use the Python
dictionary data structure). A short sample of entries
from the dictionary looks like this:
nuv person (n)
Har believe (v)
pIvghor warp-drive (n)
veS war (n)
vuv respect (v)
‘u’ universe (n)
SoH you (pro)
‘Itlh advanced (adj)
Each line consists of a word in Binarian followed by its English meaning, and the type of the
word in parentheses (n stands for noun, v for verb, adj for adjective, pro for pronoun, conj for
conjunction, num for numbers, adv for adverbials, excl for exclamation, ques for question). You
may assume that each word has exactly one translation.
The file that contains the original and whole Binarian transmission is jumbled. Some lines contain
the actual text of their message, whereas other lines that start with certain characters contain
data about Binarian race and their home-world:
 Lines that start with ‘+’ contain astrophysical data about the Binarian planet,
 Lines that start with ‘#’ contain metadata,
 All other lines form the whole Binarian message when pieced together.
A short abstract from the file that contains the whole transmission looks like this:
SoH Haup tera’nuv maHa ‘abaD tlhInganA HuSD
‘ea yuQ xenu ‘ea polagh of roj yong maHaDz ‘u’
maHa yaj ‘e’ SoH ‘abaD ‘e law’D ral jeD qur
+ Hata 11001 poaD
Segh SoH HoH Hoc manga pIzba’ vay meq jeD QaH
+ bav’Do 1011111
+ chuqD 100100 wovben
nuvDa HeghD ‘baD Hegha maHa tlhap’D ‘oH SIvaD’
maHaDzH ‘baD tlhab maHaDz ‘u’ HuSD DuHa’D ‘e qabDH
Your first mission is to extract the whole message text from the file binarian_transmission.txt
(only the message, not any other included data!) and translate it word-for-word and line-by-line
into English using the Binarian-English Dictionary. If a word is not in the dictionary, it should
stay as it is (do not omit the word in your translation!). You should both output your translation
to the console and store it in a file named binarian_message.txt.
Note 1.0: Use the template Python file and work on it. Add your name and
ID in the comment at the top of the template. For this part of the mission, complete the functions
read_dictionary() and binarian_to_english().
Note 1.1: Do not worry about capitalization and punctuation. Binarians don’t use either in their
language; hence, your output should be the exact word-for-word translation. You may assume
that there will be single spaces between the words in the input file.
Fall 2016
BBM 103: Introduction to Programming Laboratory I Programming Assignment 3
2. Mission: Data Extraction and Calculations (35 pts)
Binarians don’t use decimal number system like us; they use binary numbers. You need to uncover
all numerical data about their home-planet hidden in their transmission (hint: remember that
lines holding the astrophysical data about Binarian planet start with a ‘+’ sign).
Your second mission involves extracting numerical data from their transmission and presenting
it in a human-readable form. Since the numbers will be binary, you need to convert them into
numbers in base ten. For this part of the mission, complete the function binary_to_decimal()
in the template file, which you will use for the number base conversion.
You are supposed to find the distance of their planet from the earth in light-years, temperature
of their planet, and its orbital-speed. One extra task for you to do is to convert the obtained
distance in light-years to kilometers. You do not need to convert orbital-speed and temperature
values as they are already given in km/s and degrees Celsius respectively. For this part of the
mission, complete the function ly_to_km() in the template file, which you will use for converting
light-years to kilometers.
Note 2.0: Assume that 1 light-year equals 9.4607e+12 km (if confused about this number format,
please look up scientific e notation). Your result must also be in scientific notation (for example,
if the distance were 60 light-years, your result should be 5.676419999999999e+14 km).
Note 2.1: Assume that the distance will be given following the word “distance”, temperature
following the word “temperature”, and orbital-speed following the word “orbital-speed” (in
Binarian language of course!).
Your program should produce output of the exact form as following:
Data about Binarian planet:
Distance from the Earth: __ km
Planet temperature: __ degrees Celsius
Orbital speed: __ km/s
Where __ is replaced by values that you will calculate. We expect the formatting of your program
output to exactly match this.
You should both output your results to the console and store them in a file named
3. Mission: Translate a Message for Peace to Binarian Language (35 pts)
Your last mission is to translate a message of peace into Binarian language, which will then be
transmitted in hope that it will be enough to prove that we are indeed an intelligent and peaceful
race, and that we do not deserve to be obliterated from this planet.
The message to be translated is given in the text file named peace_message.txt. A short excerpt
from the message looks like this:
Binarians, our fellow inhabitants of this universe, we greet you in peace. It
is very unfortunate that our first encounter happened under such terrible
circumstances. Although you have every right to think that we are nothing but
a barbaric race which does not deserve this beautiful planet Earth, we assure
you that we are much more than that. We wish to prove you this by first letting
you know that we decrypted your transmission and learned some interesting
things about your planet. You call it Xenu, but here on Earth we call it HD
85512 b.
Fall 2016
BBM 103: Introduction to Programming Laboratory I Programming Assignment 3
Note 3.0: In the English message, some words will be capitalized. All English words in the
dictionary consist of lowercase letters only. Therefore, you need to be careful when looking up a
word to be translated (hint: make sure the word you are looking up in the dictionary is lowercase).
You do not have to worry about word capitalization in Binarian language; their language is not
case sensitive (i.e. letters ‘a’ and ‘A’ are different letters for example). When you find the word
you are looking for, use it in its dictionary form. For the simplicity of your task, assume that
grammar is irrelevant. Word-for-word and line-by-line translation is expected. If a word is not in
the dictionary, it should stay as it is (do not omit the word in your translation!).
Note 3.1: In the English message, you can also expect some punctuation marks: period ‘.’, comma
‘,’, exclamation mark ‘!’, and question mark ‘?’. You should get rid of them before looking the
words up in the dictionary. You are not expected to place them in the translation! Remember:
there is no punctuation in Binarian language.
Note 3.2: There will also be numbers included in the message. You need to convert them to
binary numbers before including them in the translation.
For this part of the mission, complete the functions english_to_binarian() and
decimal_to_binary() in the template file (hint: you already have the Binarian-English
Dictionary. Think about how you can create a reversed dictionary). decimal_to_binary()
function will convert a number in base ten to a binary number.
Your program should output the translated message, line by line (not as a single string!), both
to the console and into the text file named message.txt.
4. Submission Notes
 Compile your code on before submitting your work to make sure it
compiles without any problems on our server.
 Do not miss the submission deadline. Late submissions will not be accepted.
 Save all your work until the assignment is graded.
 You may discuss the problems with your classmates and TAs and ask questions on Piazza,
but you cannot share algorithms or source code. All work must be individual! Assignments
will be checked for similarity, and there will be serious consequences if plagiarism is detected.
 Do not post private questions on Piazza or via e-mail. Asking openly will not only help other
students with the same problem, but it will also help you get more answers from your
classmates as well as your TAs.
 Zip all your files (not .rar, only .zip files are supported by the system) and submit your work
through with the following file hierarchy:
 Do not include any other text files in your submission. You are expected to parse the input
file names from the command-line (see Week 5 Lab Handout). You may assume that the
input files will be given as arguments in the following order: dictionary.txt,
binarian_transmission.txt, peace_message.txt.
* * *
And that’s all! You may have just saved the whole human race from total
annihilation. You should be proud of yourself.