Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. class Message(object):
  2. def __init__(self, text):
  3. '''
  4. Initializes a Message object
  5.  
  6. text (string): the message's text
  7.  
  8. a Message object has two attributes:
  9. self.message_text (string, determined by input text)
  10. self.valid_words (list, determined using helper function load_words)
  11. '''
  12. self.message_text = text
  13. self.valid_words = load_words(WORDLIST_FILENAME)
  14.  
  15. def get_message_text(self):
  16. '''
  17. Used to safely access self.message_text outside of the class
  18.  
  19. Returns: self.message_text
  20. '''
  21. return self.message_text
  22.  
  23. def get_valid_words(self):
  24. '''
  25. Used to safely access a copy of self.valid_words outside of the class.
  26. This helps you avoid accidentally mutating class attributes.
  27.  
  28. Returns: a COPY of self.valid_words
  29. '''
  30. return self.valid_words
  31.  
  32. def build_shift_dict(self, shift):
  33. '''
  34. Creates a dictionary that can be used to apply a cipher to a letter.
  35. The dictionary maps every uppercase and lowercase letter to a
  36. character shifted down the alphabet by the input shift. The dictionary
  37. should have 52 keys of all the uppercase letters and all the lowercase
  38. letters only.
  39.  
  40. shift (integer): the amount by which to shift every letter of the
  41. alphabet. 0 <= shift < 26
  42.  
  43. Returns: a dictionary mapping a letter (string) to
  44. another letter (string).
  45. '''
  46. lower_keys = list(string.ascii_lowercase)
  47. lower_values = list(string.ascii_lowercase)
  48. shift_lower_values = lower_values[shift:] + lower_values[:shift]
  49.  
  50. upper_keys = list(string.ascii_uppercase)
  51. upper_values = list(string.ascii_uppercase)
  52. upper_shift_values = upper_values[shift:] + upper_values[:shift]
  53.  
  54.  
  55. def apply_shift(self, shift):
  56. '''
  57. Applies the Caesar Cipher to self.message_text with the input shift.
  58. Creates a new string that is self.message_text shifted down the
  59. alphabet by some number of characters determined by the input shift
  60.  
  61. shift (integer): the shift with which to encrypt the message.
  62. 0 <= shift < 26
  63.  
  64. Returns: the message text (string) in which every character is shifted
  65. down the alphabet by the input shift
  66. '''
  67. pass #delete this line and replace with your code here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement