Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit beefe94

Browse files
done
1 parent 82f592a commit beefe94

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

‎Caesar-Cipher/README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Caesar-cipher:
2+
Caesar's cipher, the shift cipher, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet.
3+
4+
5+
### How to run this:
6+
7+
```python
8+
python3 caesar_cipher.py
9+
```
10+
11+
> Learn more about this [here.](https://www.youtube.com/watch?v=fR8rVR72a6o)

‎Caesar-Cipher/caesar_cipher.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
2+
'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
3+
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
4+
5+
def caesar(text1, shift1, direction1):
6+
end_text = ''
7+
if direction=='decode':
8+
shift1 *= -1
9+
10+
for char in text1:
11+
if char in alphabet:
12+
position = alphabet.index(char)
13+
new_position = position + shift1
14+
end_text += alphabet[new_position]
15+
else:
16+
end_text += char
17+
print(f'The {direction1}d text is: {end_text}.')
18+
19+
20+
should_continue = True
21+
while should_continue:
22+
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
23+
text = input("Type your message:\n").lower()
24+
shift = int(input("Type the shift number:\n"))
25+
shift = shift % 25
26+
27+
caesar(text, shift, direction)
28+
choice=input("Type 'yes' to continue otherwise type 'no'.\n")
29+
if choice == 'no':
30+
should_continue=False

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /