-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
1 parent
35f0771
commit 25f422b
Showing
2 changed files
with
23 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#this program is a simple caesar cipher, which encrypts | ||
#a message by shifting each letter three to the right in the alphabet | ||
#this will ignore all characters that are not letters | ||
|
||
def caesar_encrypt(plaintext): | ||
#each letter in plaintext | ||
finalstring= "" | ||
for letter in plaintext.lower(): | ||
#get the number value of the letter | ||
cipher = (ord(letter)+3) | ||
#wraparound | ||
#checks letter to see if it's out of range | ||
if cipher > 122: | ||
cipher -= 26 | ||
finalstring += chr(cipher) | ||
#skips any other characters | ||
elif (ord(letter)) in range (97,123): | ||
finalstring +=chr(cipher) | ||
else: | ||
continue | ||
return(finalstring) |