Learn Caesar Cipher Encryption & Decryption in Python 3 πŸ”

Discover how to implement Caesar Cipher in Python 3 with complete code examples for encrypting and decrypting messages. Show your support πŸ‘πŸ» if this helps!

Learn Caesar Cipher Encryption & Decryption in Python 3 πŸ”
Arvin Babaei
57 views β€’ Sep 22, 2020
Learn Caesar Cipher Encryption & Decryption in Python 3 πŸ”

About this video

Give a thumbs up πŸ‘πŸ» if my code was useful to you.

Showing compilation and execution of my code in Python 3, which is capable of Encrypting, Decrypting, Brute force Attacking using Caesar Cipher cryptography.
#python #sublime #caesarcipher #cryptography

Develop a single program using any programming language (e.g. Java, Python, C++, etc) that:
a. Encrypts and decrypts a message using Cesar’s Cipher. The user encrypting the message is prompted to enter a message and then a key that indicates the displacement. The user decrypting the message is prompted to enter the encrypted message and the key.
b. Decrypts and displays all (26) possible solutions.


# Writen by Arvin Babaei
#Caesar Cipher cryptography code in Python 3
def encrypt(message, key):
encrypt_str = ''
for ch in message:
if ch.isupper():
encrypt_str += chr(ord('A') + ((ord(ch) - ord('A') + key + 26) % 26))
elif ch.islower():
encrypt_str += chr(ord('a') + ((ord(ch) - ord('a') + key + 26) % 26))
else:
encrypt_str += ch
return encrypt_str

def decrypt (message, key):
decrypt_str = ''
for ch in message:
if ch.isupper():
decrypt_str += chr(ord('A') + ((ord(ch) - ord('A') - key + 26) % 26))
elif ch.islower():
decrypt_str += chr(ord('a') + ((ord(ch) - ord('a') - key + 26) % 26))
else:
decrypt_str += ch
return decrypt_str

def brute (message, key):
brute_str = ''
for ch in message:
if ch.isupper():
brute_str += chr(ord('A') + ((ord(ch) - ord('A') - key + 26) % 26))
elif ch.islower():
brute_str += chr(ord('a') + ((ord(ch) - ord('a') - key + 26) % 26))
else:
brute_str += ch
return brute_str

if __name__ == '__main__':
while True:
input_message = input("Enter message: ")

option = input("Encrypt(E) or Decrypt(D) or Brute froce (B)?: ")
if option.lower() == 'e':
shift_amount = int(input("Enter key: "))
print(encrypt(input_message, shift_amount))
elif option.lower() == 'd':
shift_amount = int(input("Enter key: "))
print(decrypt(input_message, shift_amount))
elif option.lower() == 'b':
for shift_amount in range(26):
print ("using key: " + str(shift_amount))
print(brute(input_message, shift_amount))
else:
print("please enter valid input")
go_again = input("Go again?(Y/N):")
if go_again.lower() == 'n':
break;

Video Information

Views

57

Likes

2

Duration

0:24

Published

Sep 22, 2020

Related Trending Topics

LIVE TRENDS

Related trending topics. Click any trend to explore more videos.

Trending Now