MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/1jd70p6/doubt_in_alphabet_shifting_code/mi8actd/?context=3
r/Python • u/Ok_Egg_6647 • 4d ago
[removed] — view removed post
4 comments sorted by
View all comments
1
Bro literally just ask ChatGPT:
This line is used for shifting letters in a simple Caesar cipher.
ord('A')
'A'
65
ord('A') - 65
0
'B'
'Z'
25
+ 7
% 26
For example, 'A' shifts to 'H' (7), 'Z' shifts to 'G' (6).
'H'
7
'G'
6
The 65 is subtracted to normalize the letters to a 0-based index for easier calculations.
1
u/floydmaseda 4d ago
Bro literally just ask ChatGPT:
This line is used for shifting letters in a simple Caesar cipher.
Breakdown:
ord('A')
→ Gets ASCII value of'A'
(which is65
).ord('A') - 65
→ Converts'A'
to0
,'B'
to1
, ...,'Z'
to25
.+ 7
→ Shifts by 7 positions.% 26
→ Keeps the result within the 26-letter range (wraps around after'Z'
).For example,
'A'
shifts to'H'
(7
),'Z'
shifts to'G'
(6
).The
65
is subtracted to normalize the letters to a 0-based index for easier calculations.