Advertisement
exDotaPro

song_encryption

Jul 23rd, 2020 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. def valid_artist(artist_name):
  2.     valid_name = True
  3.     if artist_name[0].isupper():
  4.         for ch in artist_name[1:]:
  5.             if not ch.islower() and ch not in [' ', "'"]:
  6.                 valid_name = False
  7.                 break
  8.     else:
  9.         valid_name = False
  10.     return valid_name
  11.  
  12.  
  13. def valid_song(song_name):
  14.     valid_name = True
  15.     for ch in song_name:
  16.         if ch.islower() and ch != ' ':
  17.             valid_name = False
  18.             break
  19.     return valid_name
  20.  
  21.  
  22. def encrypt_string(my_key, my_string):
  23.     encrypted_string = ''
  24.     for ch in my_string:
  25.         if ch not in [' ', "'"]:
  26.             char = ord(ch) + my_key
  27.             if ch.isupper():
  28.                 if char > ord('Z'):
  29.                     char -= ord('Z')
  30.                     char += ord('A') - 1
  31.             elif ch.islower():
  32.                 if char > ord('z'):
  33.                     char -= ord('z')
  34.                     char += ord('a') - 1
  35.         else:
  36.             char = ord(ch)
  37.         encrypted_string += chr(char)
  38.     return encrypted_string
  39.  
  40.  
  41. while True:
  42.     line = input().split(':')
  43.  
  44.     if line[0] == 'end':
  45.         break
  46.  
  47.     artist, song = line[0], line[1]
  48.     if valid_artist(artist) and valid_song(song):
  49.         encrypted_artist, encrypted_song = encrypt_string(len(artist), artist), encrypt_string(len(artist), song)
  50.         print(f'Successful encryption: {encrypted_artist}@{encrypted_song}')
  51.     else:
  52.         print('Invalid input!')
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement