Skip to content

Commit 25f422b

Browse files
authored
Create caesarcipher.py (DhanushNehru#306)
* Create caesarcipher.py This is a simple example of a Caesar Cipher for Hacktoberfest- this is my first-ever pull request! :) * Updated README to include program in list
1 parent 35f0771 commit 25f422b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ More information on contributing and the general code of conduct for discussion
4141
| Autocomplete Notes App | [AutoCert](https://github.com/DhanushNehru/Python-Scripts/tree/master/Autocomplete%20Notes%20App) | A Python script to auto-generate e-certificates in bulk. |
4242
| Automated Emails | [Automated Emails](https://github.com/DhanushNehru/Python-Scripts/tree/master/Automate%20Emails%20Daily) | A Python script to send out personalized emails by reading a CSV file. |
4343
| Black Hat Python | [Black Hat Python](https://github.com/DhanushNehru/Python-Scripts/tree/master/Black%20Hat%20Python) | Source code from the book Black Hat Python |
44-
| Blackjack | [Blackjack](https://github.com/DhanushNehru/Python-Scripts/tree/master/Blackjack) | A game of Blackjack - let's get a 21. |
44+
| Blackjack | [Blackjack](https://github.com/DhanushNehru/Python-Scripts/tree/master/Blackjack) | A game of Blackjack - let's get a 21.
45+
|Caesar Cipher | [Caesar Cipher](https://github.com/rusty-bytes7/Python-Scripts/blob/e94c8b52d313dc0d66b9ed0b55032c4470f72475/caesarcipher.py) | A Python script to encrypt messages using the Caesar cipher. |
4546
| Chessboard | [Chessboard](https://github.com/DhanushNehru/Python-Scripts/tree/master/Chess%20Board) | Creates a chessboard using matplotlib. |
4647
| Compound Interest Calculator | [Compound Interest Calculator](https://github.com/DhanushNehru/Python-Scripts/tree/master/Calculate%20Compound%20Interest) | A Python script to calculate compound interest. |
4748
| Countdown Timer | [Countdown Timer](https://github.com/DhanushNehru/Python-Scripts/tree/master/Countdown%20Timer) | Displays a message when the Input time elapses. |

caesarcipher.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#this program is a simple caesar cipher, which encrypts
2+
#a message by shifting each letter three to the right in the alphabet
3+
#this will ignore all characters that are not letters
4+
5+
def caesar_encrypt(plaintext):
6+
#each letter in plaintext
7+
finalstring= ""
8+
for letter in plaintext.lower():
9+
#get the number value of the letter
10+
cipher = (ord(letter)+3)
11+
#wraparound
12+
#checks letter to see if it's out of range
13+
if cipher > 122:
14+
cipher -= 26
15+
finalstring += chr(cipher)
16+
#skips any other characters
17+
elif (ord(letter)) in range (97,123):
18+
finalstring +=chr(cipher)
19+
else:
20+
continue
21+
return(finalstring)

0 commit comments

Comments
 (0)