0% found this document useful (0 votes)
24 views7 pages

Project Alternative

Uploaded by

hpj60163
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

Project Alternative

Uploaded by

hpj60163
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

How to Confuse Your Enemy:

On Simple Encryption and Decryption Approaches

Project Description: There is often a need to send across information in a secure way to
avoid eavesdropping by other people. Encryption is the most common way to scramble the
message intended to send with a shared secret key. The sender uses the secret key to encrypt
the message, called the plaintext, into the incomprehensible ciphertext for sending. The
receiver uses the same secret key to decrypt the received ciphertext to recover the original
plaintext message. In this project, you are to implement some of the common but simple
algorithms to perform encryption and decryption, given a key. It can be assumed that the text
consists only of English letters, numbers, and punctuations.

Objective: The primary objective of this project is to build a few functions for carrying out
encryption and decryption based on a secret key. A small program consisting of a menu can
be built to connect the functions together for simple practical usage.

Project Overview:
The first step to do the project is to understand the simple encryption and decryption
algorithms. For each algorithm, two related functions are defined as the next step with the
data and key as the input parameters. One function is to carry out the encryption and the other
decryption. Each function will return the ciphertext and recovered plaintext respectively. In
the final step, a simple program is developed accepting user inputs from the keyboard or from
files, and carry out the selected functionality.

Instructions:

1. User Menu and Main Program:


o Define a main menu to be used by the user, providing the choices to the
encryption algorithms in (2).
2. Algorithm Definition:
o Caesar’s Cipher: This is the simplest one, just by shifting around all letters
by a fixed number of positions. The original Caesar’s cipher does not consider
about encrypting numbers and punctuations. Here, we assume that the
numbers are shifted in the same way as the letters, and punctuations are not
changed. It is easy to break this kind of cipher.
o Substitution Cipher: This is a generalization of Caesar’s cipher, in setting up
a mapping table for each letter to another letter in the alphabet. Mapping tables
for numbers and punctuations can also be set up. It is not hard to break this
cipher, if the ciphertext is of sufficient length. This can be achieved by
guessing the mapping table based on frequency distribution of English letters.
o Transposition Cipher: The input data is written in the form of a matrix, row
by row. The ciphertext will be generated by reading out the matrix data
column by column. The column order can also be part of the key to make the
encryption more secure. If the number of columns (and the ordering) can be
guessed correctly, the cipher can be broken.
3. Observation and Analysis:
o Try out some message to be encrypted and comment on the relative strength of
the encryption algorithms (the ability to fool the enemy and the inability of
being broken by the enemy).
4. Documentation:
o Document your code thoroughly with comments explaining each key step.
o Write a report summarizing your program design and usage.
5. Bonus Components:
o The inclusion of additional functionalities, e.g., allowing the use of files for
larger amount of data, being able to handle encryption of punctuation in
Caesar’s cipher, allowance of user input of alternative mapping tables, ability
to handle different column orders in encrypting and decrypting, other useful
features or variation in approaches, etc.

Expected Outcomes:
By the end of this project, you should:
- Gain hands-on experience in the development of a medium-sized program that
supports a variety of functionalities in an organized manner.
- Understand how to apply programming techniques to solve small-scale practical
problems.
- Develop skills in simple analysis with different testing data.
- Learn to document the methodology and findings clearly and effectively.

Conclusion:
This project aims at developing a program to allow users to encrypt and decrypt their data
using a few common and simple encryption algorithms. You will enhance your programming
ability by designing a well-documented program with proper design and organization. By
following the outlined steps and utilizing the provided code structure, you will successfully
complete the project to yield a usable program for other users. For any questions or further
assistance, feel free to reach out!

The Encryption Approaches:

Caesar’s Cipher

Please refer to Slide 77 to 79 in Lecture 7 for explanation. The encryption function in the
slide can only handle upper case letters, but the decryption function in the slide can handle
also upper case letters. You can compare the functions to gain your knowledge.

Substitution Cipher

The following shows a table of letter mapping from plaintext to ciphertext. A plaintext
message will be converted into ciphertext based on the mapping table. Here is a typical
mapping table, based on the simple keyboard order (which can be easily guessed).
a b c d e f g h i j k l m n o p q r s t u v w x y z
q w e r t y u i o p a s d f g h j k l z x c v b n m
Following the table above, “hello” will be encrypted into “itssg” and “vgksr” will be
decrypted back into “world”.

Transposition Cipher

The following shows how a message is converted into ciphertext. It involves writing plaintext
in rows and reading out the ciphertext in columns. For example, assuming that we use N = 3
columns to encrypt the plaintext message “hellohowdoyoudo” (left hand side), we write
the letters horizontally and read them out vertically in column. We then get the ciphertext as
“hlooueowydlhdoo”. Note that there is normally no space in the plaintext or ciphertext,
to reduce the chance that someone can break the ciphertext at the space location. Similarly,
we can get the ciphertext in case that some columns are not full (right hand side).
h e l h e l
l o h e o w
o w d  hlooueowydlhdoo o r l  hlodeeorblwly
o y o d b y
u d o e

Decrypting the message will involve a reversed procedure as above. Given ciphertext
“hlooueowydlhdoo” with N = 3 columns, you will fill in every five letters (15/N = 5) in
the ciphertext in each column: column 1, then 2, then 3. The plaintext can then be read out
horizontally. Likewise, you can recover “helloworldbye” from “hlodeeorblwly”.
However, care must be taken as to handle the slightly shorter columns (in this case, column 2
and column 3) in this case.

A more secure transposition cipher allows a column reading order as part of the key. Using
the example above, assuming that we use N = 3 columns to encrypt the plaintext message
“hellohowdoyoudo”, we write the letters horizontally and read them out vertically in a
column order as specified by the key, e.g. 2, 3, 1 (second column, followed by third column,
and then first column) as “eowydlhdoohloou” for the ciphertext. In this case, we can say
that the key is [3, (2, 3, 1)], or in other convenient form.
h e l
l o h
o w d  eowydlhdoohloou
o y o
u d o

To decrypt, from the ciphertext “eowydlhdoohloou” with key [3, (2, 3, 1)], you will fill
in every five letters in the ciphertext in column order of 2, 3 and 1 respectively into the 5 x 3
matrix and then read out the letters horizontally as usual. It will be much more challenging if
some of the columns are not full.
How to Confuse Your Enemy: On Simple Encryption and Decryption Approaches

Here is a sample program for the main menu. In order to use this program, you have to define
the appropriate functions for encryption and decryption. Some samples are also shown here.

# Here is the main program


def main():
while True: # repeat until Q/q
# show menu and receive user request
print("C: Caesar\nS: Substitution\nT: Transposition\nQ: Quit")
request = input("Please select algorithm: ")
if request not in ["C","c","S","s","T","t","Q","q"]:
print("Wrong choice, please try again")
elif request == "C" or request == "c": # Caesar
caesar()
elif request == "S" or request == "s": # Substitution
subst()
elif request == "T" or request == "t": # Transposition
trans()
else: # it can only be Q/q here
break

# The main program requires calls to the three algorithms, as functions:


# def caesar(): you can use your own function name
# The sample code is shown see below
# def subst(): # no key is needed for substitution cipher
# print("You have chosen substitution")
# def trans():
# print("You have chosen transposition")
def caesar(): # caesar cipher
print("Please enter Caesar key (1 to 25): ",end="")
k = int(input()) # use one of them, or your own way
# k = eval(input())
print("Please enter your data:")
data = input()
while True: # repeat until getting E/e/D/d
print("E: encryption\tD: decryption: ",end="")
request = input()
if request in "EeDd": # shorthand for <in ["E","e","D","d"]>
break
if request in "Ee": # encryption
ciphertext = caesar_enc(data,k)
print("The ciphertext:")
print(ciphertext)
if request in "Dd": # decryption
plaintext = caesar_dec(data,k)
print("The recovered plaintext:")
print(plaintext)

# Sample caesar_enc() – slide 78 of lecture 7 – can only handle A to Z


def caesar_enc(msg, key=3): # pass in the message to encrypt
print("Encrypting '{}' with key {}".format(msg,key))
encoded = "" # empty string to store encoded message
for ch in msg: # each character in the message
e = ord(ch)-key # encrypt it
if e < ord('A'):
e = e + 26 # wrap back around
encoded = encoded + chr(e) # append the encoded char
return encoded # you can also use join() as before
Here are some sample outputs from sample executions, upon completing the remaining
functions. You do not need to follow the text or organization exactly as in the samples.

C: Caesar C: Caesar
S: Substitution S: Substitution
T: Transposition T: Transposition
Q: Quit Q: Quit
Please select algorithm: A Please select algorithm: t
Wrong choice, please try again Please enter transposition columns: 3
C: Caesar Please enter your data:
S: Substitution hereisanexample
T: Transposition E: encryption D: decryption: e
Q: Quit Encrypting 'hereisanexample' with key 3
Please select algorithm: C The ciphertext:
Please enter Caesar key (1 to 25): 5 heaxpeinalrseme
Please enter your data: C: Caesar
HelloWorld S: Substitution
E: encryption D: decryption: E T: Transposition
Encrypting 'Hello World' with key 5 Q: Quit
The ciphertext: Please select algorithm: T
CzggjRjmgy Please enter transposition columns: 5
C: Caesar Please enter your data:
S: Substitution HSAEAMRNPEELIXE
T: Transposition E: encryption D: decryption: d
Q: Quit Decrypting 'hsaeamrnpeelixe' with key 5
Please select algorithm: c The recovered plaintext:
Please enter Caesar key (1 to 25): 10 HEREISANEXAMPLE
Please enter your data: C: Caesar
xem QHU oek DEM? S: Substitution
E: encryption D: decryption: d T: Transposition
Decrypting 'xem QHU oek DEM?' with key 1 Q: Quit
0 Please select algorithm: t
The recovered plaintext: Please enter transposition columns: 4
how ARE you NOW? Please enter your data:
C: Caesar transpositioncipher
S: Substitution E: encryption D: decryption: e
T: Transposition Encrypting 'transpositioncipher' with ke
Q: Quit y 4
Please select algorithm: s The ciphertext:
Please enter your data: tsinhrptceaoiirnsop
here is an example C: Caesar
E: encryption D: decryption: e S: Substitution
Encrypting 'here is an example' with key T: Transposition
qwertyuiopasdfghjklzxcvbnm Q: Quit
The ciphertext: Please select algorithm: t
itkt ol qf tbqdhst Please enter transposition columns: 6
C: Caesar Please enter your data:
S: Substitution tarliehleepxioxfhtsnaoeigmrrsepct
T: Transposition E: encryption D: decryption: D
Q: Quit Decrypting 'tarliehleepxioxfhtsnaoeigmrr
Please select algorithm: S sepct' with key 6
Please enter your data: The recovered plaintext:
ol oz royyoexsz? thisisalongerexampleforciphertext
E: encryption D: decryption: d C: Caesar
Decrypting 'ol oz royyoexsz' with key qw S: Substitution
ertyuiopasdfghjklzxcvbnm T: Transposition
The recovered plaintext: Q: Quit
is it difficult? Please select algorithm: Q
Project Deliverables:

You are required to submit the following deliverables:

1. Final Report:
o You are required to write the report describing your program design, key data
structures, and how you tackle potentially difficult logic. Interesting findings
in program development or execution can be provided with explanations and
using examples.
o The report should be of at least 10 pages. It must adhere to a plagiarism
threshold of less than 30%, which can be checked on Blackboard or any third-
party website.
o The report should consist of the following subsections:

 Abstract
 Introduction
 Program design
 Implementation issues
 Discussion and/or findings
 Conclusion
 Appendix (useful content not suitable to be placed in main text)

Ensure that each section is well-developed and contributes to the overall narrative of
your project.

o Your report will be evaluated based on the quality of your writing and the
attention given to formatting. For example: ensuring equations are written
neatly, all references, if any, adhere to a consistent and neat referencing style,
both in the reference section and throughout the report, etc.
2. Code Files:
o All relevant code files used should be submitted, ensuring reproducibility of
the results.
3. Formatted Documents:
o The final report should be submitted in .pdf format, with a consistent
formatting style. You can refer to popular journals for examples, e.g. papers
from IEEExplore or ACM Digital Library (both sites accessible via PolyU
library).

By following these guidelines, you will create a cohesive report that effectively documents
your development and communicates your findings.

Demonstration

You should make a video (in MP4 format) to introduce the application in brief (about 3 to 5
minutes max) and submit it together with the source code and the project report on or before the
due date on the Blackboard. If your video is large size or due to any reason is not uploaded to the
blackboard then you should upload it elsewhere and share the link (you should ensure that the
video link has open shared access and not restricted to the instructors and the TA’s.)

The deadline for project submission is Saturday, November 23, 2024.

Late submissions will be penalized.

Marks distribution
The mark distribution of this project is as follows:

Implementation: 65 %
Documentation: 30 %
Demonstration: 5 %
Bonus: 10 Points

Submission

You must submit the following files (except Item 4) in ONE zipped file and upload it to the
Blackboard System:

1. Readme file – write down your project title and the name of each member in your group,
together with all necessary information that may be required to run your program; name the
file as "Readme_Gxx.txt" where "Gxx" is your Group number assigned.

For BONUS points: You should clearly state what extra modules and components you have
implemented.

2. Source code and output files


➢ Name of the source code file should be "SC_Gxx.c.". All the modules including
the BONUS modules and components should be written in a single source code file.

3. Name the project report as "Project_Report_Gxx.pdf".

4. Name the demo video file as "demo_Gxx.mp4" (Use MP4 format for your video. If the
file size of the video is too large, send us a link to download it.)

You might also like