Home>

### python : Problem with displacement in Caesar cipher

Standard Caesar cipher. The problem is in the calculated formula, if the displacement is given greater than the length of the alphabet. I expect when shifting 1, the letter A will become, and when the 34 letter, I will become A. I do not understand what poured in numbers.

``````eng_lower_alphabet= 'abcdefghijklmnopqrstuvwxyz'
ENG_UPPER_ALPHABET= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
rus_lower_alphabet= "ABVGDEZHZYCHCHCHEYYEYAYA"
rus_upper_alphabet= "ABVGDEZHZIKHCHCHYEYYYYUKHEYU"
Symbol= ["", ",", ".", "!", "?"]
DEF SHIFT (I, OFFSET):
if i.isalpha ():
if i in eng_lower_alphabet:
Print (ENG_LOWER_ALPHABET [(ORD (I) + (OFFSET% 26)) -97])
if i in rus_lower_alphabet:
Print (RUS_LOWER_ALPHABET [(ORD (I) + (OFFSET% 33)) -1072])
If i in eng_upper_alphabet:
Print (ENG_UPPER_ALPHABET [(ORD (I) + (OFFSET% 26)) -65])
if i in rus_upper_alphabet:
Print (RUS_UPPER_ALPHABET [(ORD (I) + (OFFSET% 33)) -1040])
Print ("Enter the letter")
phrase= input ()
Shift (Phrase, 1088)
``````

Error:

``````Indexerror Traceback (MOST Recent Call Last)
≪
ipython-input-99-1f3e9ddd2432 >
in <
Module >
18 PRINT ("Enter the letter")
19 phrase= input ()
--->
20 SHIFT (Phrase, 1088)
21.
22.
≪
ipython-input-99-1f3e9ddd2432 >
In Shift (I, Offset)
10 Print (ENG_LOWER_ALPHABET [(ORD (I) + (OFFSET% 26)) -97])
11 if i in rus_lower_alphabet:
--->
12 Print (RUS_LOWER_ALPHABET [(ORD (I) + (OFFSET% 33)) -1072])
13 if i in eng_upper_alphabet:
14 PRINT (ENG_UPPER_ALPHABET [(ORD (I) + (OFFSET% 26)) -65])
Indexerror: String Index Out of Range
``````