代做CMPUT 331, Winter 2025, Assignment 1代写留学生Python语言

CMPUT 331, Winter 2025, Assignment 1

Before beginning work on this assignment, carefully read the Assignment Submission Specifications posted on Canvas.

Introduction

The Caesar Cipher does not offer much security as the number of keys is small enough to allow a brute-force approach to cryptanalysis. However, with some modifications, it can be greatly improved. In this assignment, you will modify the Caesar Cipher implemented by the textbook (“caesarCipher.py”) to improve its encryption strength.

You will produce five files for this assignment:

• a1p1.py, a1p2.py, a1p3.py: python solutions to problems 1, 2, and 3 respectively

• a1.txt: written responses to problem 4

• a README file (README.txt or README.pdf)

Submit your files in a zip file named 331-as-1.zip.

Problem 1 (2 Marks)

For this problem, modify the provided skeleton file, “a1p1.py”. You may use the provided “caesarCipher.py” file as reference to implement three functions named “get map”, “encrypt”, and “decrypt”.

The function “get map” takes one argument:

• letters: a string of letters such as “AaBbCcDd...”, where each letter corresponds to its shift amount 0, 1, 2, 3, 4, 5, ..., 51

The “get map” function plays a crucial role in establishing the connections between letters and their respective shift amounts. It should return two dictionaries: the first mapping each letter to its corresponding shift, and the second allowing the reverse mapping of shifts to their respective letters. These dictionaries are essential references for the other functions, for example, enabling efficient querying of shift amounts based on the given letter. While the default argument value is “AaBbCcDd...”, your implementation should seamlessly accommodate others, such as “ZzYyXxWw...”. These variations will be tested during the assignment evaluation. Example output of “get map”:

char_to_index = {‘A’: 0, ‘B’: 1, ‘C’: 2, ...}

index_to_char = {0: ‘A’, 1: ‘B’, 2: ‘C’, ...}

The “encrypt” and “decrypt” functions take two arguments:

• message: plaintext string to encrypt

• key: one of the 52 uppercase/lowercase letters corresponding to the shift amounts, for instance, A = 0, a = 1, B = 2, b = 3, C = 4, c = 5... etc.

The “encrypt” function should return the message string such that each letter has been caesar-shifted by the key amount. Non-letters characters (such as spaces or punctuation) are to be appended to the resulting string unmodified. The “decrypt” function should reverse the shift performed by encrypt and return the original plaintext. The following demonstrates invocation sequences that should run without error and produce identical output:

python3 -i a1p1.py

>>> test(); encrypt("AaBbCcDd...", "x")

‘xYyZzAaB...’

>>> test(); decrypt("xYyZzAaB...", "x")

‘AaBbCcDd...’

>>> test(); encrypt("Welcome to 2025 Winter CMPUT 331!", "x")

‘tCJAMKC RM 2025 tGLRCP zjmrq 331!’

>>> test(); decrypt("tCJAMKC RM 2025 tGLRCP zjmrq 331!", "x")

‘Welcome to 2025 Winter CMPUT 331!’

>>> test(); encrypt("This is Problem 1 of Assignment 1.", "y")

‘rGHR HR nQNAKDL 1 NE yRRHFMLDMS 1.’

>>> test(); decrypt("rGHR HR nQNAKDL 1 NE yRRHFMLDMS 1.", "y")

‘This is Problem 1 of Assignment 1.’

Problem 2 (2 Marks)

One weakness of the Caesar Cipher comes from the fact that every letter is enciphered the same way. If the first letter of the message is shifted forward by three positions, every letter is shifted forward by three positions. Let’s start by fixing this flaw. Make a copy of your “a1p1.py” code named “a1p2.py” and modify it such that:

1. The first letter of the message is shifted according to the chosen key, exactly as before (i.e. for encryption a key of “b” shifts the first letter up by 3).

2. All remaining letters are shifted using the previous letter of the message (plaintext) as a key. If the previous character is punctuation, use the letter before it.

python3 -i a1p2.py

>>> test(); encrypt("AaBbCcDd...", "y")

‘yabcdefg...’

>>> test(); decrypt("yabcdefg...", "y")

‘AaBbCcDd...’

>>> test(); encrypt("Welcome to 2025 Winter CMPUT 331!", "y")

‘uaQORBR YI 2025 keWHYW tOBJN 331!’

>>> test(); decrypt("uaQORBR YI 2025 keWHYW tOBJN 331!", "y")

‘Welcome to 2025 Winter CMPUT 331!’

>>> test(); encrypt("This is Problem 2 of Assignment 1.", "x")

‘qaQB BB hgGQNQR 2 BU fsLBPUARSH 1.’

>>> test(); decrypt("qaQB BB hgGQNQR 2 BU fsLBPUARSH 1.", "x")

‘This is Problem 2 of Assignment 1.’

Problem 3 (2 Marks):

Now make another copy of your “a1p1.py” code and name it “a1p3.py” (Note: copy a1p1.py and not a1p2.py). Modify your encrypt and decrypt functions so that the key is a string instead of a single letter. We will call this string the keyword. Modify your code so that it enciphers a message as follows:

1. If the keyword is n characters long, then the 1st, 2nd, 3rd..., and nth letters of the message are enciphered using the 1st, 2nd, 3rd..., and nth letters of keyword respectively. You may assume that the keyword only contains upper and lowercase letters. If the message is shorter than the keyword then the extra characters in the keyword are to be ignored.

2. The rest of the string is enciphered using the above method except as if the (n+1)th character is the beginning of the string.

Note that non-letter characters (such as spaces, punctuation, and numbers) will not be encrypted. When encountering these characters, the encryption process will simply skip them and resume with the next letter. Here is an example:

encrypt("Welcome to 2025 Winter CMPUT 331!", "XxYyZz")

It should work as follows:

XxYyZzX xY yZzXxY yZzXx

Welcome to 2025 Winter CMPUT 331!

TCjBnMb Rm 2025 uhNqCp aLoRq 331!

In this example, the letters above the plaintext represent the key used to encrypt the plaintext into the ciphertext. Spaces indicate that no key is applied. Specifically, “X” is the key used to encrypt the first letter “W”. Numbers, such as “2025”, and punctuation marks, such as “!”, are not encrypted, so no key is applied to them.

python3 -i a1p3.py

>>> test(); encrypt("AaBbCcDd...", "XxYyZz")

‘XYZABCAB...’

>>> test(); decrypt("XYZABCAB...", "XxYyZz")

‘AaBbCcDd...’

>>> test(); encrypt("Welcome to 2025 Winter CMPUT 331!", "XxYyZz")

‘TCjBnMb Rm 2025 uhNqCp aLoRq 331!’

>>> test(); decrypt("TCjBnMb Rm 2025 uhNqCp aLoRq 331!", "XxYyZz")

’Welcome to 2025 Winter CMPUT 331!’

>>> test(); encrypt("This is Problem 3 of Assignment 1.", "ZYXzyx")

‘SffS HQ OplBKCl 3 mc zRQhekMDLs 1.’

>>> test(); decrypt("SffS HQ OplBKCl 3 mc zRQhekMDLs 1.", "ZYXzyx")

‘This is Problem 3 of Assignment 1.’

Problem 4 (4 Marks)

For this problem, consider the encryption strength of the original caesar cipher and each of your modified ciphers. Some of the ciphers, multiple valid keys that result in plaintext being enciphered in the same way. Please record your answers in the provided file “a1.txt” for the following questions.

4a: How many distinct keys, keys which each produce different ciphertexts for the same message, do each of the four ciphers have?

4b: Is the problem 2 cipher stronger than the original caesar cipher?

4c: Will encrypting the space help address the weaknesses of the Caesar cipher?

Note: Please strictly follow the template provided in a1.txt. Any change in the template might result in a potential mark deduction.




热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图