联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2020-04-01 10:23

Problem Solving and

Programming

Programming

Assignment 1

School of Computer and Information Science

INTRODUCTION

This document describes the first assignment for Problem Solving and Programming.

The assignment is intended to provide you with the opportunity to put into practice what you have learnt in the course

by applying your knowledge and skills to the implementation of a simple encryption technique.

This assignment is an individual task that will require an individual submission. If you are an internal student,

you will be required to submit your work via learnonline before Monday 6 April, 11.30pm. Internal students are not

required to demonstrate in person.

This document is a kind of specification of the required end product that will be generated by implementing the

assignment. Like many specifications, it is written in English and hence will contain some imperfectly specified parts.

Please make sure you seek clarification if you are not clear on any aspect of this assignment.

ASSIGNMENT OVERVIEW

Caesar Cipher

You are required to write a Python program that performs simple encryption and decryption on strings entered by the

user. To do so, you are to use one of the simplest and most widely known encryption techniques known as the

Caesar Cipher. The Caesar Cipher is named after Julius Caesar who used it for private correspondence.

Please ensure that you read the section titled 'Caesar Cipher Specification' below for further details.

4 of 20

GRADUATE QUALITIES

By undertaking this assessment, you will progress in developing the qualities of a University of South Australia

graduate.

The Graduate qualities being assessed by this assignment are:

? The ability to demonstrate and apply a body of knowledge (GQ1) gained from the lectures, workshops,

practicals and readings. This is demonstrated in your ability to apply problem solving and programming

theory to a practical situation.

? The development of skills required for lifelong learning (GQ2), by searching for information and learning to use

and understand the resources provided (Python standard library, lectures, workshops, practical exercises,

etc); in order to complete a programming exercise.

? The ability to effectively problem solve (GQ3) using Python to complete the programming problem. Effective

problem solving is demonstrated by the ability to understand what is required, utilise the relevant information

from lectures, workshops and practical work, write Python code, and evaluate the effectiveness of the code by

testing it.

? The ability to work autonomously (GQ4) in order to complete the task.

? The use of communication skills (GQ6) by producing code that has been properly formatted; and writing

adequate, concise and clear comments.

? The application of international standards (GQ7) by making sure your solution conforms to the standards

presented in the Python Style Guide slides (available on the course website).

5 of 20

CAESAR CIPHER SPECIFICATION

Write a menu driven program called yourEmailId_encryptor.py that will allow the user to enter commands and

process these commands until the quit command is entered. Your program will accept entry of a string and an offset

value from the keyboard and encrypt or decrypt it as requested.

A simple way to encrypt data is attributed to Julius Caesar, the Roman Emperor. (If you are interested, you may like

to read the following… http://en.wikipedia.org/wiki/Caesar_cipher). This method takes each character in a message

and replaces it with one which is a certain distance (offset) along the alphabet from it (moving right).

For example:

If the offset is 3 then A becomes D, B becomes E, C becomes F etc. In this case the word DIG encrypts to GLJ. In

order to decrypt the word/string, simply offset by the same amount moving in the opposite direction (i.e. moving left).

Instead of restricting the cipher to the alphabetic characters only, we will use all of the printable ASCII characters.

That is, all the characters from ASCII 32 (Space) to ASCII 126 (~).

The following commands should be allowed:

1. Encrypt string:

Prompt for and read (from the keyboard) a string to be encrypted. The program should then ask for the offset

value (limited to a range of 1 to 94 inclusive). Display the encrypted string to the screen.

2. Decrypt string:

Decrypt an encrypted message by prompting for and reading (from the keyboard) a string to be decrypted.

The program should then ask for the offset value (limited to the range of 1 to 94 inclusive). Display the

decrypted string to the screen.

3. Brute force decryption:

If the offset is not known, we can implement a brute force decryption algorithm that tries all of the 94 possible

Caesar offsets in order to decrypt the encrypted text. Prompt for and read the string to be decrypted and

display all 94 possible decrypted strings to the screen. (If you are interested, you may like to read the

following… http://en.wikipedia.org/wiki/Brute-force_attack).

4. Quit:

Quits the program displaying a goodbye message to the screen.

6 of 20

Please note:

Your program must work with the printable ASCII character set. That is, all the characters from ASCII 32 (Space) to

ASCII 126 (~). When the offset points to a character beyond 126 it should wrap around to the beginning of the set.

For Example:

If the offset is 4 and the character is ‘}’ (ASCII 125) then it will encrypt to ASCII 129. This is beyond 126 so wrap back

to the beginning by subtracting the total number of characters (95). This gives character 34. Similarly when

decrypting, if the subtracted offset results in a number less than 32 then add 95 to the result.

You will need to make use of the following two functions:

ord(c)

Given c, a string of length one ord(c), returns an integer (ASCII value) representing the value of the string.

For example: ord('a') returns the integer 97.

chr(i)

Returns a string of one character whose ASCII value is the integer i.

For example: chr(97) returns the string 'a'.

7 of 20

PRACTICAL REQUIREMENTS

It is recommended that you develop this part of the assignment in the suggested stages.

It is expected that your solution WILL include the use of:

? Your solution in one file called yourEmailId_encryptor.py.

? Appropriate and well constructed while and/or for loops (as necessary).

? Appropriate if, if-else, if-elif-else statements (as necessary).

? The use of the ord() and chr() functions (as necessary).

? The concatenation (+) or augmented operator (+=) operator to create/build new strings.

? Output that strictly adheres to the assignment specifications. If you are not sure about these details, you

should check with the ‘Sample Output’ provided at the end of this document or post a message to the

discussion forum for clarification.

? Good programming practice:

o Consistent commenting, layout and indentation. You are to provide comments to describe: your

details, program description, all variable definitions, and every significant section of code.

o Meaningful variable names (no single letter identifier names).

? Your solution MAY use:

o Any of the Python built-in functions… specifically, you may find you may need the following: int(),

input(), print(), range(), ord(),and chr().

? Your solutions MAY ALSO make use of the following:

o Access the individual elements in a string with an index (one element only). i.e.

string_name[index].

Your solutions MUST NOT use:

? break, or continue statements in your solution. Do not use the quit() or exit() functions or the break

or return statements (or any other techniques) as a way to break out of loops. Doing so will result in a

significant mark deduction.

? Your own (user-defined) functions.

PLEASE NOTE: You are reminded that you should ensure that all input and output conform to the

specifications listed here; if you are not sure about these details you should check with the sample output

provided at the end of this document or post a message to the discussion forum in order to seek clarification.

Please ensure that you use Python 3.8.2 or a later version (i.e. the latest version) in order to complete your

assignments. Your programs MUST run using Python 3.8.2 (or latest version).

8 of 20

STAGES

It is recommended that you develop this part of the assignment in the suggested stages. Many problems in later

stages are due to errors in early stages. Make sure you have finished and thoroughly tested each stage before

continuing.

The following stages of development are recommended:

Stage 1

Implement the interactive mode (prompt for and read menu commands). Set up a loop to obtain and process

commands. Test to ensure that this is working correctly before moving onto stage 2. You need not perform any

encryption/decryption of text at this point, you may simply display an appropriate message to the screen.

Sample output:

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 1

In command 1 - encrypt string

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 2

In command 2 - decrypt string

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 3

In command 3 - brute force

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 4

Goodbye.

Make sure the program runs correctly. Once you have that working, back up your program. Note: When developing

software, you should always have fixed points in your development where you know your software is bug free and

runs correctly.

9 of 20

Stage 2

Add code to implement command 1. Encrypt string.

Prompt for and read a string to be encrypted. Prompt for and read the offset value (limited to a range of 1 to 94

inclusive). Create and display the encrypted string to the screen. You must use the concatenation (+) or augmented

operator (+=) operator to create/build the encrypted string.

Please note:

Your program must work with the printable ASCII character set. That is, all the characters from ASCII 32 (Space) to

ASCII 126 (~). When the offset points to a character beyond 126 it should wrap around to the beginning of the set.

For Example:

If the offset is 4 and the character is ‘}’ (ASCII 125) then it will encrypt to ASCII 129. This is beyond 126 so wrap back

to the beginning by subtracting the total number of characters (95). This gives character 34. Similarly when

decrypting, if the subtracted offset results in a number less than 32 then add 95 to the result.

You will need to make use of the following two functions:

ord(c)

Given c, a string of length one ord(c), returns an integer (ASCII value) representing the value of the string.

For example: ord('a') returns the integer 97.

chr(i)

Returns a string of one character whose ASCII value is the integer i.

For example: chr(97) returns the string 'a'.

Sample output:

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 1

Please enter string to encrypt: secret squirrel

Please enter offset value (1 to 94): 6

Encrypted string:

ykixkz&yw{oxxkr

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 4

Goodbye.

10 of 20

Stage 3

Add code to implement command 2. Decrypt string.

Prompt for and read a string to be decrypted. Prompt for and read the offset value (limited to a range of 1 to 94

inclusive). Create and display the decrypted string to the screen. You must use the concatenation (+) or augmented

operator (+=) operator to create/build the decrypted string.

Please note:

Your program must work with the printable ASCII character set. That is, all the characters from ASCII 32 (Space) to

ASCII 126 (~). When the offset points to a character beyond 126 it should wrap around to the beginning of the set.

For Example:

If the offset is 4 and the character is ‘}’ (ASCII 125) then it will encrypt to ASCII 129. This is beyond 126 so wrap back

to the beginning by subtracting the total number of characters (95). This gives character 34. Similarly when

decrypting, if the subtracted offset results in a number less than 32 then add 95 to the result.

You will need to make use of the following two functions:

ord(c)

Given c, a string of length one ord(c), returns an integer (ASCII value) representing the value of the string.

For example: ord('a') returns the integer 97.

chr(i)

Returns a string of one character whose ASCII value is the integer i.

For example: chr(97) returns the string 'a'.

Sample output:

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 2

Please enter string to decrypt: ykixkz&yw{oxxkr

Please enter offset value (1 to 94): 6

Decrypted string:

secret squirrel

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 4

Goodbye.

11 of 20

Stage 4

Add code to implement command 3. Brute force decryption.

Prompt for and read a string to be decrypted. Display all 94 possible decrypted strings to the screen.

Please note:

Your program must work with the printable ASCII character set. That is, all the characters from ASCII 32 (Space) to

ASCII 126 (~). When the offset points to a character beyond 126 it should wrap around to the beginning of the set.

For Example:

If the offset is 4 and the character is ‘}’ (ASCII 125) then it will encrypt to ASCII 129. This is beyond 126 so wrap back

to the beginning by subtracting the total number of characters (95). This gives character 34. Similarly when

decrypting, if the subtracted offset results in a number less than 32 then add 95 to the result.

Sample output:

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 3

Please enter string to decrypt: ykixkz&yw{oxxkr

Offset: 1 = Decrypted string: xjhwjy%xvznwwjq

Offset: 2 = Decrypted string: wigvix$wuymvvip

Offset: 3 = Decrypted string: vhfuhw#vtxluuho

Offset: 4 = Decrypted string: ugetgv"uswkttgn

Offset: 5 = Decrypted string: tfdsfu!trvjssfm

Offset: 6 = Decrypted string: secret squirrel

Offset: 7 = Decrypted string: rdbqds~rpthqqdk

Offset: 8 = Decrypted string: qcapcr}qosgppcj

Offset: 9 = Decrypted string: pb`obq|pnrfoobi

Offset: 10 = Decrypted string: oa_nap{omqennah

:

: you get the idea… :)

:

Offset: 87 = Decrypted string: "sq!s#." $w!!sz

Offset: 88 = Decrypted string: !rp r"-!~#v ry

Offset: 89 = Decrypted string: qo~q!, }"u~~qx

Offset: 90 = Decrypted string: ~pn}p +~|!t}}pw

Offset: 91 = Decrypted string: }om|o~*}{ s||ov

Offset: 92 = Decrypted string: |nl{n})|z~r{{nu

Offset: 93 = Decrypted string: {mkzm|({y}qzzmt

Offset: 94 = Decrypted string: zljyl{'zx|pyyls

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 4

Goodbye.

12 of 20

Stage 5

Add code to validate the following user input only:

? What would you like to do [1,2,3,4]?

Sample output:

What would you like to do [1,2,3,4]? 7

Invalid choice, please enter either 1, 2, 3 or 4.

What would you like to do [1,2,3,4]?

? Please enter offset value (1 to 94):

Sample output:

Please enter offset value (1 to 94): 101

Please enter offset value (1 to 94): -1

Please enter offset value (1 to 94): 3

Stage 6 – THIS IS IMPORTANT!

Finally, check the sample output (see section titled ‘Sample Output’) and if necessary, modify your code so

that:

? The output produced by your program EXACTLY matches the sample output provided.

? Your program EXACTLY behaves as described in these specs and the sample output provided.

13 of 20

SUBMISSION DETAILS

You are required to do the following in order to submit your work and have it marked:

? You are required to submit an electronic copy of your program via learnonline before Monday 6 April,

11.30pm.

All students must follow the submission instructions below:

Ensure that your files are named correctly (as per instructions outlined in this document).

Ensure that the following files are included in your submission:

? yourEmailId_encryptor.py

For example:

? bonjy007_encryptor.py

All files that you submit must include the following comments.

#

# File: fileName.py

# Author: your name

# Email Id: your email id

# Description: Assignment 1 – place assignment description here…

# This is my own work as defined by the University's

# Academic Misconduct policy.

#

Assignments that do not contain these details may not be marked.

You must have submitted your program before the online due date. Work that has not been correctly submitted to

learnonline will not be marked.

It is expected that students will make copies of all assignments and be able to provide these if required.

14 of 20

EXTENSIONS AND LATE SUBMISSIONS

There will be no extensions/late submissions for this course without one of the following exceptions:

1. A medical certificate is provided that has the timing and duration of the illness and an opinion on how much

the student’s ability to perform has been compromised by the illness. Please note if this information is not

provided the medical certificate WILL NOT BE ACCEPTED. Late assessment items will not be accepted

unless a medical certificate is presented to the Course Coordinator. The certificate must be produced as soon

as possible and must cover the dates during which the assessment was to be attempted. In the case where

you have a valid medical certificate, the due date will be extended by the number of days stated on the

certificate up to five working days.

2. A Learning and Teaching Unit councillor contacts the Course Coordinator on your behalf requesting an

extension. Normally you would use this if you have events outside your control adversely affecting your

course work.

3. Unexpected work commitments. In this case, you will need to attach a letter from your work supervisor with

your application stating the impact on your ability to complete your assessment.

4. Military obligations with proof.

Applications for extensions must be lodged via learnonline before the due date of the assignment.

Note: Equipment failure, loss of data, ‘Heavy work commitments’ or late starting of the course are not sufficient

grounds for an extension.

ACADEMIC MISCONDUCT

ACADEMIC MISCONDUCT

Students are reminded that they should be aware of the academic misconduct guidelines available from the University

of South Australia website.

Deliberate academic misconduct such as plagiarism is subject to penalties. Information about Academic integrity can

be found in Section 9 of the Assessment policies and procedures manual at:

http://www.unisa.edu.au/policies/manual/

15 of 20

MARKING CRITERIA

16 of 20

Possible deductions:

? Programming style: Things to watch for are poor or no commenting, poor variable names, etc.

? Submitted incorrectly: -5 marks if assignment is submitted incorrectly (i.e. not adhering to the specs).

17 of 20

SAMPLE OUTPUT

Sample output 1:

File : wayby001_encryptor.py

Author : Batman

Stud ID : 0123456X

Email ID : wayby001

This is my own work as defined by the University's Academic Misconduct Policy.

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 1

Please enter string to encrypt: Elvis has left the building!

Please enter offset value (1 to 94): 3

Encrypted string:

Hoylv#kdv#ohiw#wkh#exloglqj$

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 2

Please enter string to decrypt: Hoylv#kdv#ohiw#wkh#exloglqj$

Please enter offset value (1 to 94): 3

Decrypted string:

Elvis has left the building!

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 4

Goodbye.

19 of 20

Sample output 2:

File : wayby001_encryptor.py

Author : Batman

Stud ID : 0123456X

Email ID : wayby001

This is my own work as defined by the University's Academic Misconduct Policy.

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 1

Please enter string to encrypt: Top Secret

Please enter offset value (1 to 94): 98

Please enter offset value (1 to 94): -3

Please enter offset value (1 to 94): 20

Encrypted string:

h$%4gyw'y)

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 4

Goodbye.

Sample output 3:

File : wayby001_encryptor.py

Author : Batman

Stud ID : 0123456X

Email ID : wayby001

This is my own work as defined by the University's Academic Misconduct Policy.

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 2

Please enter string to decrypt: h$%4gyw'y)

Please enter offset value (1 to 94): -2

Please enter offset value (1 to 94): 150

Please enter offset value (1 to 94): 0

Please enter offset value (1 to 94): 95

Please enter offset value (1 to 94): 20

Decrypted string:

Top Secret

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 4

Goodbye.

20 of 20

Sample output 4:

File : wayby001_encryptor.py

Author : Batman

Stud ID : 0123456X

Email ID : wayby001

This is my own work as defined by the University's Academic Misconduct Policy.

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 9

Invalid choice, please enter either 1, 2, 3 or 4.

What would you like to do [1,2,3,4]? 1

Please enter string to encrypt: one more time

Please enter offset value (1 to 94): 7

Encrypted string:

vul'tvyl'{ptl

*** Menu ***

1. Encrypt string

2. Decrypt string

3. Brute force decryption

4. Quit

What would you like to do [1,2,3,4]? 4

Goodbye.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp