Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. # Dictionary representing the morse code chart
  2. MORSE_CODE_DICT = {'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....',
  3. 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.',
  4. 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',
  5. 'Y': '-.--', 'Z': '--..', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....',
  6. '6': '-....', '7': '--...', '8': '---..', '9': '----.', '0': '-----', ', ': '--..--', '.': '.-.-.-',
  7. '?': '..--..', '/': '-..-.', '-': '-....-', '(': '-.--.', ')': '-.--.-'}
  8.  
  9. # Function to encrypt the string
  10. # according to the morse code chart
  11. def encrypt(message):
  12. cipher = ''
  13. for letter in message:
  14. if letter != ' ':
  15.  
  16. # Looks up the dictionary and adds the
  17. # correspponding morse code
  18. # along with a space to separate
  19. # morse codes for different characters
  20. cipher += MORSE_CODE_DICT[letter] + ' '
  21. else:
  22. # 1 space indicates different characters
  23. # and 2 indicates different words
  24. cipher += ' '
  25.  
  26. return cipher
  27.  
  28. print encrypt(raw_input('input text: ').upper())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement