FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms/algorithms/strings/caesar_cipher.py at master · lualgorithm/algorithms · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
lualgorithm
/
algorithms
Public
forked from
keon/algorithms
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms
/
algorithms
/
strings
/
caesar_cipher.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
19 lines (18 loc) · 694 Bytes
Breadcrumbs
algorithms
/
algorithms
/
strings
/
caesar_cipher.py
Copy path
File metadata and controls
19 lines (18 loc) · 694 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""
Julius Caesar protected his confidential information by encrypting it using a cipher.
Caesar's cipher shifts each letter by a number of letters. If the shift takes you
past the end of the alphabet, just rotate back to the front of the alphabet.
In the case of a rotation by 3, w, x, y and z would map to z, a, b and c.
Original alphabet: abcdefghijklmnopqrstuvwxyz
Alphabet rotated +3: defghijklmnopqrstuvwxyzabc
"""
def
caesar_cipher
(
s
,
k
):
result
=
""
for
char
in
s
:
n
=
ord
(
char
)
if
64
<
n
<
91
:
n
=
((
n
-
65
+
k
)
%
26
)
+
65
if
96
<
n
<
123
:
n
=
((
n
-
97
+
k
)
%
26
)
+
97
result
=
result
+
chr
(
n
)
return
result
Back
|
FazBrowse Home
|
New Git URL