0% found this document useful (0 votes)
18 views1 page

Task 1

cypher to plain txt coding (cybersecurity)

Uploaded by

fayoyo8571
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

Task 1

cypher to plain txt coding (cybersecurity)

Uploaded by

fayoyo8571
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Task 1

def caesar_cipher_encrypt(text, shift):


# Encrypts the input text using the Caesar Cipher with the given shift value.
encrypted_text = ""
for char in text:
if char.isalpha():
# Determine if the character is uppercase or lowercase
if char.islower():
shift_base = ord('a')
else:
shift_base = ord('A')
# Shift the character and wrap around the alphabet if necessary
encrypted_char = chr((ord(char) - shift_base + shift) % 26 +
shift_base)
encrypted_text += encrypted_char
else:
# Non-alphabet characters are not changed
encrypted_text += char
return encrypted_text

def caesar_cipher_decrypt(text, shift):


# Decrypts the input text using the Caesar Cipher with the given shift value.
return caesar_cipher_encrypt(text, -shift)

def main():
# Main function to handle user input and perform encryption or decryption
action = input("Would you like to (E)ncrypt or (D)ecrypt? ").strip().upper()
text = input("Enter the message: ")
shift = int(input("Enter the shift value: "))

if action == 'E':
result_text = caesar_cipher_encrypt(text, shift)
print(f"Encrypted Text: {result_text}")
elif action == 'D':
result_text = caesar_cipher_decrypt(text, shift)
print(f"Decrypted Text: {result_text}")
else:
print("Invalid option. Please choose 'E' for encryption or 'D' for
decryption.")

if __name__ == "__main__":
main()

You might also like