-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtechnest_python_problem_set_4_2
More file actions
63 lines (50 loc) · 2.17 KB
/
technest_python_problem_set_4_2
File metadata and controls
63 lines (50 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class PlaintextMessage(Message):
def __init__(self, text, shift):
'''
Initializes a PlaintextMessage object
text (string): the message's text
shift (integer): the shift associated with this message
A PlaintextMessage object inherits from Message and has five attributes:
self.message_text (string, determined by input text)
self.valid_words (list, determined using helper function load_words)
self.shift (integer, determined by input shift)
self.encrypting_dict (dictionary, built using shift)
self.message_text_encrypted (string, created using shift)
Hint: consider using the parent class constructor so less
code is repeated
'''
Message.__init__(self, text)
self.shift = shift
self.encrypting_dict = self.build_shift_dict(shift)
self.message_text_encrypted = self.apply_shift(shift)
pass #delete this line and replace with your code here
def get_shift(self):
'''
Used to safely access self.shift outside of the class
Returns: self.shift
'''
return self.shift
def get_encrypting_dict(self):
'''
Used to safely access a copy self.encrypting_dict outside of the class
Returns: a COPY of self.encrypting_dict
'''
return self.encrypting_dict.copy()
def get_message_text_encrypted(self):
'''
Used to safely access self.message_text_encrypted outside of the class
Returns: self.message_text_encrypted
'''
return self.message_text_encrypted
def change_shift(self, shift):
'''
Changes self.shift of the PlaintextMessage and updates other
attributes determined by shift (ie. self.encrypting_dict and
message_text_encrypted).
shift (integer): the new shift that should be associated with this message.
0 <= shift < 26
Returns: nothing
'''
self.shift = shift
self.encrypting_dict = self.build_shift_dict(shift)
self.message_text_encrypted = self.apply_shift(shift)