$24
Q1
Q2
Q3
Points
30 points
20 points
50 points
Read General rules at the end of homework and make sure that you named files correctly.
Q1)
GTU Encoding Table
Assume that we are in a terrible science war. All universities sniff
Char
Code
each other’s network and try to understand what they are doing.
E
0
In the cold science war you are expected to send messages not as
I
10
plain text but as encrypted text.
Space
110
T
1110
Yes, you are the chosen one and all you have and need is GTU
C
11110
encoding table and your amazing coding skills! Table is given
left… Note that it only includes a part of the alphabet. The
N
111110
remaining characters are not going to be encrypted.
A
1111110
G
11111110
Objectives
B
111111110
1. Read the plain text message from PlainMessagesToSent.txt
Z
1111111110
file
H
11111111110
2.
Write the encoded message to EncodedMessages.txt file
L
111111111110
3. Crypt encoded messages by reading encoded messages file
U
1111111111110
and changing each ‘1’ with ‘*’ and ‘0’ with ‘_’, also add ‘-‘
V
11111111111110
symbol according to following rule:
R
111111111111110
Add a ‘-‘ symbol after each M characters. M starts with N and
S
1111111111111110
decreased by one after adding a ‘-‘ symbol until M is equal to
Y
11111111111111110
zero. When M is equal to zero reinitialize it by N. N is given to
be 5.
4.
Write the encrypted message (encrypted by ‘*’ ‘_’ ‘-‘) to
EncryptedMessages.txt file
Example
Plain Text Message
IT IS BAG
Encoded Message
101110110101111111111111110110111111110111111011111110
Encrypted Message
*_***-_**_-*_*-**-*-*****-****-**_-**-_-*****-***_-***-**-*-_****-***_-
Big Picture
CALL
OPEN FILES IN MAIN
encode_and_write_
ENCODING
SEND FILE* TO
to_file(…) IN
encode_message(…)
encode_message
function
function to encode
a character
OPEN FILES IN MAIN
SEND FILE* TO
ENCRYPTION crypt_message(…)
function
GIVEN WANTED
Template_1.c Part1.c
PlainMessagesToSent.txt EncodedMessages.txt
CryptedMessages.txt
Note that you are expected to use Template_1.c file for Q1 which is attached to homework. You are going to find detailed info there also.
Q2) In this question, you are expected to read an encrypted message and convert it back to the plain text message.
Objectives
Read the encrypted message from EncryptedInput.txt which is attached to homework.
Eliminate ‘-‘ symbols and change ‘*’ to ‘1’ and ‘_’ to ‘0’ to obtain the encoded message. Write encoded message to EncodedInput.txt file.
Read the encoded input from EncodedInput.txt file.
Decode the encoded message and write the plain text message to ReceivedMessage.txt file.
Big Picture
OPEN FILES IN MAIN
SEND FILE* TO
DECRYPTION decrypt_message(…) function
CALL
OPEN FILES IN MAIN
decode_and_write_
DECODING
SEND FILE* TO
to_file(…) IN
decode_message(…)
decode_message
function
function to decode
a character
GIVEN WANTED
Template_2.c Part2.c
CryptedInput.txt EncodedInput.txt
ReceivedMessage.txt
Note that you are expected to use Template_2.c file for Q2 which is attached to homework. You are going to find detailed info there also.
Q3) Now it is time to decode X University’s messaging system! Assume X University uses a heuristic to create encoding table. Their heuristic is just based on frequency of letters. Frequently used letters have shorter code length.
Example
Character List
A B C
Sample
AABABAABCBAAC
Frequency List of Sample
Char
A
B
C
Counts
7
4
2
Encoding Table of Sample
Char
A
B
C
Code
0
10
110
Encoded Message of X University
11010010011000110
Plain Text Message of X University
CBABACAAC
Objectives
You are given CharacterList.txt including three characters which are the letters of messaging system’s alphabet. However, since the file is recovered from their trash it is broken (it contains some extra characters which are not a part of their alphabet). You should ignore all characters which are not letter like ‘!’, ‘=’,’+’ etc. Write a function to figure out three letters and return number of letters read.
Read the file Sample.txt and count letters to find their frequencies and sort them to according to frequency. Implement swap functions given in template c file. You are going to use swap functions while sorting numbers and characters.
Since you figured out frequency of letters thanks to count letters function, you can handle decoding process. Decode the messages in XUniversityEncoded.txt file. Write the decoded (plain text) message to XUniversityMessage.txt file
Big Picture
LEARNING
READ CharacterList to
READ Sample to learn
learn letters of
encoding codes of
ALPHABET
alphabet
letters
OPEN FILES IN MAIN
SEND FILE* TO
DECODING decode_message(…)
function
GIVEN WANTED
Template_3.c Part3.c
CharacterList.txt XUniversityMessage.txt
Sample.txt
XUniversityEncoded.txt
Note that you are expected to use Template_3.c file for Q3 which is attached to homework. You are going to find detailed info there also.
General:
Obey honor code principles.
Obey coding convention.
Read your homework carefully and follow the directives about the I/O format (data filenames, file formats, etc.) and submission format strictly. Violating any of these directives will be penalized.
Your submission should include the following file and NOTHING MORE (no data files, object files, etc):
HW04_<student name_<student surname_<student number_part1.c
HW04_<student name_<student surname_<student number_EncodedMessages.txt HW04_<student name_<student surname_<student number_CryptedMessages.txt HW04_<student name_<student surname_<student number_part2.c HW04_<student name_<student surname_<student number_EncodedInput.txt HW04_<student name_<student surname_<student number_ReceivedMessage.txt HW04_<student name_<student surname_<student number_part3.c HW04_<student name_<student surname_<student number_XUniversityMessage.txt
Do not use non-English characters in any part of your homework (in body, file name, etc.).
Deliver the printout of your work until the last submission date.