safe computing concerns
safe computing Notes and Homework
Notes
Types of Encryption Symmetric Encryption (Private Key Encryption) The same key is used for both encryption and decryption Faster but requires securely sharing the key between parties Example: AES (Advance Encryption Standard) used for securing files Asymmetric Encryption (Public Key Encryption) Uses a pair of keys: Public Key (for encryption) Private key (for decryption) More secure for internet communications since users don’t need to share a single key. Hashing (One-way encryption) Converts data into a fixed length string that cannot be reversed Used for storing passwordss securely. Example: SHA-256 (Secure Hash Algorithm) used in blockchain and password security.
- To prevent this, we must
- never click on links in texts from unknown numbers
- never contact our bank or service provider directly if we recieve a suspicious text
- and enable spam filters on our phones to block spam messages
import random
def caesar_cipher(text, shift, mode):
result = ""
shift = shift % 26 # Ensure shifts wrap around correctly
if mode not in ["encrypt", "decrypt"]:
return "Invalid mode! Please enter 'encrypt' or 'decrypt'."
for char in text:
if char.isalpha():
shift_amount = shift if mode == "encrypt" else -shift
new_char = chr(((ord(char.lower()) - 97 + shift_amount) % 26) + 97)
result += new_char.upper() if char.isupper() else new_char
else:
result += char
return result
# User input with basic validation
mode = input("Do you want to encrypt or decrypt? ").strip().lower()
if mode not in ["encrypt", "decrypt"]:
print("Invalid mode! Please enter 'encrypt' or 'decrypt'.")
else:
message = input("Enter your message: ")
shift_input = input("Enter shift value (number of places to shift or 'random'): ").strip().lower()
if shift_input == "random":
shift = random.randint(1, 25) # Pick a random shift value between 1 and 25
print(f"Random shift selected: {shift}")
else:
try:
shift = int(shift_input)
except ValueError:
print("Invalid shift value! Please enter a number or 'random'.")
shift = None
if shift is not None:
output = caesar_cipher(message, shift, mode)
print(f"Result: {output}")
Result: xn
- ✅ Allows “random” as a shift input – The user can type “random”, and the program will select a random integer between 1 and 25.
- ✅ Prints the selected random shift – So the user knows what shift was applied.
- ✅ Preserves original functionality – Users can still input a manual shift value if they prefer.
- ✅ Handles invalid inputs – Ensures only valid numbers or “random” are accepted.