Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def caesar_work(_direction, _language, _step, _string):
- string_arr = list(_string)
- if _direction == 'E' and _language == 'EN':
- for i in range(len(string_arr)):
- if string_arr[i].isupper():
- if ord(string_arr[i])+ _step > ord('Z'):
- string_arr[i] = chr(ord(string_arr[i]) + _step - 26)
- else:
- string_arr[i] = chr(ord(string_arr[i]) + _step)
- elif string_arr[i].islower():
- if ord(string_arr[i])+ _step > ord('z'):
- string_arr[i] = chr(ord(string_arr[i]) + _step - 26)
- else:
- string_arr[i] = chr(ord(string_arr[i]) + _step)
- elif _direction == 'E' and _language == 'RU':
- for i in range(len(string_arr)):
- if string_arr[i].isupper():
- if ord(string_arr[i])+ _step > ord('Я'):
- string_arr[i] = chr(ord(string_arr[i]) + _step - 32)
- else:
- string_arr[i] = chr(ord(string_arr[i]) + _step)
- elif string_arr[i].islower():
- if ord(string_arr[i])+ _step > ord('я'):
- string_arr[i] = chr(ord(string_arr[i]) + _step - 32)
- else:
- string_arr[i] = chr(ord(string_arr[i]) + _step)
- elif _direction == 'D' and _language == 'RU':
- for i in range(len(string_arr)):
- if string_arr[i].isupper():
- if ord(string_arr[i])+ _step < ord('А'):
- string_arr[i] = chr(ord(string_arr[i]) - _step + 32)
- else:
- string_arr[i] = chr(ord(string_arr[i]) - _step)
- elif string_arr[i].islower():
- if ord(string_arr[i])+ _step < ord('а'):
- string_arr[i] = chr(ord(string_arr[i]) - _step + 32)
- else:
- string_arr[i] = chr(ord(string_arr[i]) - _step)
- elif _direction == 'D' and _language == 'EN':
- for i in range(len(string_arr)):
- if string_arr[i].isupper():
- if ord(string_arr[i])+ _step < ord('A'):
- string_arr[i] = chr(ord(string_arr[i]) - _step + 26)
- else:
- string_arr[i] = chr(ord(string_arr[i]) - _step)
- elif string_arr[i].islower():
- if ord(string_arr[i])+ _step < ord('a'):
- string_arr[i] = chr(ord(string_arr[i]) - _step + 26)
- else:
- string_arr[i] = chr(ord(string_arr[i]) - _step)
- string_result = ''.join(string_arr)
- print(string_result)
- print("Let's encrypt or decrypt your phrase")
- print()
- direction = input('Encryption or decryption? Enter E or D: ', )
- while direction != 'E' and direction != 'D':
- direction = input('Please enter E or D! ')
- language = input('What language do you want to use? Enter RU or EN: ')
- while language != 'RU' and language != 'EN':
- language = input('Please enter RU or EN! ')
- step = input('What shear step do you want to use? Enter an integer number: ')
- while step.isdigit() == False:
- step = input('Please enter an integer number: ')
- step = int(step)
- string = input('Enter a string: ')
- caesar_work(direction, language, step, string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement