Advertisement
kompilainenn

Untitled

Jan 19th, 2023
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.23 KB | None | 0 0
  1. def caesar_work(_direction, _language, _step, _string):
  2.  
  3.     string_arr = list(_string)
  4.     if _direction == 'E' and _language == 'EN':
  5.         for i in range(len(string_arr)):
  6.             if string_arr[i].isupper():
  7.                 if ord(string_arr[i])+ _step > ord('Z'):
  8.                     string_arr[i] = chr(ord(string_arr[i]) + _step - 26)
  9.                 else:
  10.                     string_arr[i] = chr(ord(string_arr[i]) + _step)
  11.             elif string_arr[i].islower():
  12.                 if ord(string_arr[i])+ _step > ord('z'):
  13.                     string_arr[i] = chr(ord(string_arr[i]) + _step - 26)
  14.                 else:
  15.                     string_arr[i] = chr(ord(string_arr[i]) + _step)
  16.     elif _direction == 'E' and _language == 'RU':
  17.         for i in range(len(string_arr)):
  18.             if string_arr[i].isupper():
  19.                 if ord(string_arr[i])+ _step > ord('Я'):
  20.                     string_arr[i] = chr(ord(string_arr[i]) + _step - 32)
  21.                 else:
  22.                     string_arr[i] = chr(ord(string_arr[i]) + _step)
  23.             elif string_arr[i].islower():
  24.                 if ord(string_arr[i])+ _step > ord('я'):
  25.                     string_arr[i] = chr(ord(string_arr[i]) + _step - 32)
  26.                 else:
  27.                     string_arr[i] = chr(ord(string_arr[i]) + _step)
  28.     elif _direction == 'D' and _language == 'RU':
  29.         for i in range(len(string_arr)):
  30.             if string_arr[i].isupper():
  31.                 if ord(string_arr[i])- _step < ord('А'):
  32.                     string_arr[i] = chr(ord(string_arr[i]) - _step + 32)
  33.                 else:
  34.                     string_arr[i] = chr(ord(string_arr[i]) - _step)
  35.             elif string_arr[i].islower():
  36.                 if ord(string_arr[i])- _step < ord('а'):
  37.                     string_arr[i] = chr(ord(string_arr[i]) - _step + 32)
  38.                 else:
  39.                     string_arr[i] = chr(ord(string_arr[i]) - _step)
  40.     elif _direction == 'D' and _language == 'EN':
  41.         for i in range(len(string_arr)):
  42.             if string_arr[i].isupper():
  43.                 if ord(string_arr[i])- _step < ord('A'):
  44.                     string_arr[i] = chr(ord(string_arr[i]) - _step + 26)
  45.                 else:
  46.                     string_arr[i] = chr(ord(string_arr[i]) - _step)
  47.             elif string_arr[i].islower():
  48.                 if ord(string_arr[i])- _step < ord('a'):
  49.                     string_arr[i] = chr(ord(string_arr[i]) - _step + 26)
  50.                 else:
  51.                     string_arr[i] = chr(ord(string_arr[i]) - _step)
  52.     string_result = ''.join(string_arr)
  53.     print(string_result)
  54.  
  55.  
  56.  
  57. print("Let's encrypt or decrypt your phrase")
  58. print()
  59.  
  60. direction = input('Encryption or decryption? Enter E or D: ', )
  61. while direction != 'E' and direction != 'D':
  62.     direction = input('Please enter E or D! ')
  63.  
  64. language = input('What language do you want to use? Enter RU or EN: ')
  65. while language != 'RU' and language != 'EN':
  66.     language = input('Please enter RU or EN! ')
  67.  
  68. step = input('What shear step do you want to use? Enter an integer number: ')
  69. while step.isdigit() == False:
  70.     step = input('Please enter an integer number: ')
  71. step = int(step)
  72.  
  73. string = input()
  74. caesar_work(direction, language, step, string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement