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 d4d9461

Browse files
Merge pull request avinashkranjan#603 from smriti1313/caesar-cipher
Caesar cipher
2 parents 0f2bba3 + 2cd34f4 commit d4d9461

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

‎Caesar-Cipher/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
- Simply copy-paste the code in your editor and run it using:
8+
9+
```python
10+
python3 caesar_cipher.py
11+
```
12+
13+
### Output:
14+
15+
![](output.png)

‎Caesar-Cipher/caesar_cipher.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import string as st
2+
3+
letter_list=st.ascii_lowercase
4+
alphabet=[letter for letter in letter_list]*2
5+
6+
def caesar(text1, shift1, direction1):
7+
end_text = ''
8+
if direction=='decode':
9+
shift1 *= -1
10+
11+
for char in text1:
12+
if char in alphabet:
13+
position = alphabet.index(char)
14+
new_position = position + shift1
15+
end_text += alphabet[new_position]
16+
else:
17+
end_text += char
18+
print(f'The {direction1}d text is: {end_text}.')
19+
20+
21+
should_continue = True
22+
while should_continue:
23+
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
24+
text = input("Type your message:\n").lower()
25+
shift = int(input("Type the shift number:\n"))
26+
shift = shift % 25
27+
28+
caesar(text, shift, direction)
29+
choice=input("Type 'yes' to continue otherwise type 'no'.\n")
30+
if choice == 'no':
31+
should_continue=False

‎Caesar-Cipher/output.png

67.2 KB
Loading[フレーム]

0 commit comments

Comments
(0)

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