ENGG1111 Assignment 2

Topics: ASCII, Character encoding, Shopping mall Pages: 7 (1819 words) Published: November 18, 2014
The University of Hong Kong
ENGG1111 Computer Programming and Applications
Assignment 2 Deadline: 17:00 Nov 14, 2014.
CodeBreaker

Background
You and a group of colleagues meet up socially now and then at various shopping malls. The details of when and where to meet are sent out to the group in the form of text messages. To keep the details private, the messages are encoded so that they cannot be read easily; they must be decoded before they can be read.

Here is an example of an encoded message displayed as text:

Unfortunately, you lost the key needed to decode the latest message and don’t want to ask for it again. Your task in this assignment is to write a program to break the code so that you can read a message without knowing the key.

You know certain details about the messages which will make it easier to write the codebreaker: o
o

o

all messages are exactly 140 characters long;
the decoded messages will contain the name of one shopping mall. Your group meets at only 7 malls, all of which have exactly 13 characters in their names: - 1881 Heritage
- Festival Walk
- Horizon Plaza
- Langham Place
- Olympian City
- Pacific Place
- Telford Plaza
the messages are encoded using a simple scheme involving character substitution.

Encoding
Messages are encoded using a form of Caesar cipher. A Caesar Cipher encodes a message by replacing each character with the character a certain number of positions from the original. For example, using the English alphabet and shifting by 4 positions to the right, the word LOST is encoded as PSWX: ...

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

...

...

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

...

4 position shift 

The number used to specify the number of positions to shift during encoding is known as the key; in this example, the key is 4. Clearly, we can decode PSWX by shifting each character back 4 places to the left to recreate LOST.

The final issue is how to handle cases where the shift takes us beyond the last character of the alphabet for example, if we encode the character Y using a key of 4. The solution is to wrap around such that shifting beyond the last character of the alphabet takes us directly back to the first character. The shift, therefore, is best viewed as a rotation since we rotate through the characters of the alphabet continuously, and, using a key of 4, Y is encoded as C:

...

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

...

...

U

V

W

X

Y

Z

A

B

C

D

E

F

G

H

I

...

4 position rotate

Rather than simply rotating through the 26 letters of the English alphabet, the encoding scheme used by your friends rotates through the first 128 values of the ASCII character table. Dec

Char

Dec

Char

Dec

Char

Dec

Char

Example:
Plain text to encode: Meet at Pacific Place
Key used to encode: 84
Encoded text: !99Ht5Ht$57=:=7t$@579
Explanation:
- First plain text character is M, stored as the ASCII
code 77
- Shifting with a key of 84 gives a result of 161
- Wrapping around gives the encoded value 33
- The character represented by ASCII code 33 is ! thus
the first character of encoded text displays as !
And so on for each character in the plain text
message. (Text to be encoded is usually referred to as
plaintext.)

Breaking the code
To read the message from your friends you need to break the code. That is, you must work out what key was used to encode the message and then use that knowledge to decode it. Since you know that the encoding scheme involves rotating through ASCII values 0 to 127, you know that there are only 128 possible keys of interest. With such a small number of keys, we can use brute force to break the code. A brute force approach involves trying each key in turn until the correct one is found. Your program can determine whether a key is correct...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • nutrition assignment 2 Research Paper
  • Unit 2 Assignment 2 Essay
  • Studymode Assignment 205 task A 2 Essay
  • NT1210 Unit 2 Assignment 2 Essay
  • Essay about Assignment 2
  • Assignment 2 Essay
  • Assignment 2 Essay
  • Assignment 2 Essay

Become a StudyMode Member

Sign Up - It's Free