Skip to content

Commit d9818c9

Browse files
Merge pull request TheAlgorithms#10 from SergeyTsaplin/separate-directories
Move files to separate directories
2 parents d847747 + ab26145 commit d9818c9

11 files changed

+43
-38
lines changed

Caesar Cipher.py

-38
This file was deleted.

ciphers/Caesar Cipher.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# The Caesar Cipher Algorithm
2+
3+
def main():
4+
message = input("Enter message: ")
5+
key = int(input("Key [1-26]: "))
6+
mode = input("Encrypt or Decrypt [e/d]: ")
7+
8+
if mode.lower().startswith('e'):
9+
mode = "encrypt"
10+
elif mode.lower().startswith('d'):
11+
mode = "decrypt"
12+
13+
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
14+
15+
translated = ""
16+
17+
message = message.upper()
18+
19+
for symbol in message:
20+
if symbol in LETTERS:
21+
num = LETTERS.find(symbol)
22+
if mode == "encrypt":
23+
num = num + key
24+
elif mode == "decrypt":
25+
num = num - key
26+
27+
if num >= len(LETTERS):
28+
num = num - len(LETTERS)
29+
elif num < 0:
30+
num = num + len(LETTERS)
31+
32+
translated = translated + LETTERS[num]
33+
else:
34+
translated = translated + symbol
35+
36+
if mode == "encrypt":
37+
print("Encryption:", translated)
38+
elif mode == "decrypt":
39+
print("Decryption:", translated)
40+
41+
42+
if __name__ == '__main__':
43+
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)