Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def encrypt(key_length, string):
- new_string = ""
- n = len(string)
- for i in range(n):
- character_unicode = ord(string[i])
- if character_unicode == 32: # whitespace
- new_string += ' '
- continue
- elif character_unicode == 39: # apostrophe
- new_string += "'"
- continue
- elif 122 >= character_unicode and character_unicode >= 97: # lowercase
- new_character_code = (character_unicode + key_length) % 123
- if new_character_code < 97:
- new_character_code += 97
- new_string += chr(new_character_code)
- elif 90 >= character_unicode and character_unicode >= 65: # uppercase
- new_character_code = (character_unicode + key_length) % 91
- if new_character_code < 65:
- new_character_code += 65
- new_string += chr(new_character_code)
- return new_string
- if __name__ == "__main__":
- while True:
- cmd = input()
- if cmd.lower() == "end":
- break
- artist, song = cmd.split(':')
- artist_len = len(artist)
- song_len = len(song)
- # First check if the artist is valid.
- first_letter_unicode = ord(artist[0])
- if 91 <= first_letter_unicode or first_letter_unicode <= 64:
- print("Invalid input!")
- continue
- is_artist_valid = True
- for i in range(1, artist_len):
- character_unicode = ord(artist[i])
- if character_unicode == 32: # whitespace
- continue
- elif character_unicode == 39: # apostrophe
- continue
- elif 122 >= character_unicode and character_unicode >= 97:
- continue
- else:
- print("Invalid input!")
- is_artist_valid = False
- break
- if not is_artist_valid:
- continue
- # Then check the validity of the song.
- is_song_valid = True
- for i in range(song_len):
- character_unicode = ord(song[i])
- if character_unicode == 32: # whitespace
- continue
- elif 90 >= character_unicode and character_unicode >= 65:
- continue
- else:
- print("Invalid input!")
- is_song_valid = False
- break
- if not is_song_valid:
- continue
- # If everything was alright, encrypt the information.
- encrypted_artist = encrypt(artist_len, artist)
- encrypted_song = encrypt(artist_len, song)
- print("Successful encryption: %s@%s" %
- (encrypted_artist, encrypted_song))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement