Skip to content

Commit

Permalink
Create CaesarCipherEncrypt.py
Browse files Browse the repository at this point in the history
Created algorithm to encrypt any string using caesar cipher algorithm. Requires the string to encrypt and the key.
  • Loading branch information
dhavalpandey authored Oct 27, 2024
1 parent 7ccf2d2 commit 8ff6b83
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Python/CaesarCipherEncrypt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def caesar_cipher(text, key):
result = ""
for char in text:
if char.isupper():
result += chr((ord(char) + key - 65) % 26 + 65)
elif char.islower():
result += chr((ord(char) + key - 97) % 26 + 97)
else:
result += char

return result
text = input("Enter the string to encode: ")
key = int(input("Enter the shift key: "))

encoded_text = caesar_cipher(text, key)
print(f"Encoded string: {encoded_text}")

0 comments on commit 8ff6b83

Please sign in to comment.