Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Question 3

The document discusses browser URL redirection, including reasons for redirection and methods such as HTTP status codes and JavaScript redirects. It also covers Intrusion Detection Systems (IDS), detailing three models: signature-based, anomaly-based, and hybrid detection, along with their strengths and limitations. Additionally, it provides a Python program for encrypting and decrypting text using the Caesar shift cipher, highlighting its features and usage examples.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views8 pages

Question 3

The document discusses browser URL redirection, including reasons for redirection and methods such as HTTP status codes and JavaScript redirects. It also covers Intrusion Detection Systems (IDS), detailing three models: signature-based, anomaly-based, and hybrid detection, along with their strengths and limitations. Additionally, it provides a Python program for encrypting and decrypting text using the Caesar shift cipher, highlighting its features and usage examples.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

a.

Browser (URL) redirection refers to the technique of forwarding or redirecting a user's web
browser from one URL to another which could also be used for malicious purposes.
i. Mention Two(2) reasons why a URL redirection happens
ii. List Four(4) ways (with relevant examples) that a Browser (URL) is directed, i.e. Automated
Redirection instances

b. Intrusion Detection Systems (IDS) to detect unauthorized access or malicious activities within
a computer system or network.
i. Describe the Three(3) Intrusion Detection Models (IDS)
ii. State at least One(1) strength and One(1) Limitation of each model in achieving the goals of
an IDS.

c. The Caesar shift cipher is one of the oldest and simplest forms of encryption, named after
Julius Caesar, who reportedly used it in his private correspondence. Write a python program
to:
i. Encrypt input texts using the symmetric monoalphabetic Caesar shift cipher
Hint use: shifted_char = chr((ord(char) + ord('a') + shift) % 26 + ord('a')

ii. Decrypt input texts using the symmetric monoalphabetic Caesar shift cipher;
Hint use: shifted_char = chr((ord(char) - ord('a') + shift) % 26 + ord('a')

SOLUTION
a. Browser (URL) Redirection
i. Two Reasons Why URL Redirection Happens
1. Website Maintenance and Updates: Organizations redirect URLs when they restructure
their websites, move content to new locations, or undergo domain changes. This ensures
users can still access the intended content even when the original URL structure has
changed.
2. SEO and Marketing Purposes: Companies use redirects to consolidate link equity, track
marketing campaigns, create user-friendly shortened URLs, or redirect traffic from old
domains to new ones while maintaining search engine rankings.

ii. Four Ways Browser URL is Redirected (Automated


Redirection)
1. HTTP Status Code Redirects
301 Permanent Redirect: https://oldsite.com → https://newsite.com
302 Temporary Redirect: https://example.com/promo →
https://example.com/sale
2. Meta Refresh Tag
HTML: <meta http-equiv="refresh" content="5;url=https://newpage.com">
Example: A "please wait" page that automatically redirects after 5 seconds
3. JavaScript Redirects
window.location.href = "https://newdestination.com";
window.location.replace("https://replacement.com");
4. Server-Side Redirects
Apache .htaccess: Redirect 301 /oldpage.html
https://newsite.com/newpage.html
Nginx: return 301 https://newdomain.com$request_uri;

b. Intrusion Detection Systems (IDS)


i. Three Intrusion Detection Models
1. Signature-Based Detection (Misuse Detection) This model identifies intrusions by
comparing network traffic or system activities against a database of known attack patterns,
signatures, or rules. It works similarly to antivirus software, matching observed behavior
against predefined malicious patterns.
2. Anomaly-Based Detection (Behavior-Based Detection) This model establishes a
baseline of normal system or network behavior and flags activities that deviate significantly
from this baseline. It uses statistical analysis, machine learning, or heuristic methods to
identify unusual patterns that may indicate attacks.
3. Hybrid Detection This model combines both signature-based and anomaly-based
approaches to leverage the strengths of both methods. It uses signature matching for
known threats while employing behavioral analysis to detect novel or unknown attacks.

ii. Strengths and Limitations of Each Model


Signature-Based Detection:

Strength: Provides high accuracy with very low false positive rates for known attacks,
making it reliable for detecting established threats with clear patterns.
Limitation: Cannot detect new, unknown attacks (zero-day exploits) or variations of existing
attacks that don't match the signature database.

Anomaly-Based Detection:
Strength: Can detect novel attacks and zero-day exploits by identifying unusual behavioral
patterns that deviate from normal system operations.
Limitation: Generates high false positive rates due to legitimate but unusual activities being
flagged as potential threats, requiring significant tuning and analysis.

Hybrid Detection:

Strength: Combines the reliability of signature-based detection with the adaptability of


anomaly-based detection, providing comprehensive threat coverage.
Limitation: Requires more computational resources and complex management due to the
need to maintain both signature databases and behavioral baselines.

c. Caesar Shift Cipher Python Program


def caesar_encrypt(text, shift):
"""
Encrypt input text using Caesar shift cipher

Args:
text (str): The text to encrypt
shift (int): The number of positions to shift (0-25)

Returns:
str: The encrypted text
"""
encrypted_text = ""

for char in text:


if char.isalpha():
# Convert to lowercase for processing
char_lower = char.lower()
# Apply the encryption formula
shifted_char = chr((ord(char_lower) - ord('a') + shift) % 26 +
ord('a'))

# Preserve original case


if char.isupper():
encrypted_text += shifted_char.upper()
else:
encrypted_text += shifted_char
else:
# Non-alphabetic characters remain unchanged
encrypted_text += char
return encrypted_text

def caesar_decrypt(text, shift):


"""
Decrypt input text using Caesar shift cipher

Args:
text (str): The text to decrypt
shift (int): The number of positions to shift (0-25)

Returns:
str: The decrypted text
"""
decrypted_text = ""

for char in text:


if char.isalpha():
# Convert to lowercase for processing
char_lower = char.lower()
# Apply the decryption formula (shift in opposite direction)
shifted_char = chr((ord(char_lower) - ord('a') - shift) % 26 +
ord('a'))

# Preserve original case


if char.isupper():
decrypted_text += shifted_char.upper()
else:
decrypted_text += shifted_char
else:
# Non-alphabetic characters remain unchanged
decrypted_text += char

return decrypted_text

def validate_shift(shift):
"""
Validate and normalize the shift value

Args:
shift (int): The shift value to validate

Returns:
int: Normalized shift value (0-25)
"""
return shift % 26

def main():
"""
Main function to demonstrate Caesar cipher encryption and decryption
"""
print("=== Caesar Shift Cipher Program ===\n")

while True:
print("Choose an option:")
print("1. Encrypt text")
print("2. Decrypt text")
print("3. Exit")

choice = input("\nEnter your choice (1-3): ").strip()

if choice == '1':
# Encryption
text = input("Enter text to encrypt: ")
try:
shift = int(input("Enter shift value (0-25): "))
shift = validate_shift(shift)

encrypted = caesar_encrypt(text, shift)


print(f"\nOriginal text: {text}")
print(f"Shift value: {shift}")
print(f"Encrypted text: {encrypted}\n")

except ValueError:
print("Error: Please enter a valid integer for shift
value.\n")

elif choice == '2':


# Decryption
text = input("Enter text to decrypt: ")
try:
shift = int(input("Enter shift value (0-25): "))
shift = validate_shift(shift)

decrypted = caesar_decrypt(text, shift)


print(f"\nEncrypted text: {text}")
print(f"Shift value: {shift}")
print(f"Decrypted text: {decrypted}\n")

except ValueError:
print("Error: Please enter a valid integer for shift
value.\n")

elif choice == '3':


print("Goodbye!")
break

else:
print("Invalid choice. Please enter 1, 2, or 3.\n")

def brute_force_decrypt(encrypted_text):
"""
Attempt to decrypt text by trying all possible shift values

Args:
encrypted_text (str): The encrypted text to decrypt

Returns:
dict: Dictionary with shift values and corresponding decrypted text
"""
results = {}

print(f"Brute force decryption for: '{encrypted_text}'")


print("-" * 50)

for shift in range(26):


decrypted = caesar_decrypt(encrypted_text, shift)
results[shift] = decrypted
print(f"Shift {shift:2d}: {decrypted}")

return results

# Example usage and testing


if __name__ == "__main__":
# Demonstration examples
print("=== Caesar Cipher Demonstration ===\n")

# Example 1: Basic encryption and decryption


original_text = "Hello, World!"
shift_value = 3

print(f"Original text: {original_text}")


print(f"Shift value: {shift_value}")
# Encrypt
encrypted = caesar_encrypt(original_text, shift_value)
print(f"Encrypted: {encrypted}")

# Decrypt
decrypted = caesar_decrypt(encrypted, shift_value)
print(f"Decrypted: {decrypted}")

print("\n" + "="*50 + "\n")

# Example 2: Historical Caesar cipher (shift of 3)


historical_message = "The die is cast"
print(f"Historical example: '{historical_message}'")
historical_encrypted = caesar_encrypt(historical_message, 3)
print(f"Encrypted with Caesar's shift (3): '{historical_encrypted}'")

print("\n" + "="*50 + "\n")

# Example 3: Brute force demonstration


mystery_text = "Wkh txlfn eurzq ira"
brute_force_decrypt(mystery_text)

print("\n" + "="*50 + "\n")

# Run the interactive program


main()

i. Encryption Function
The encryption function uses the provided hint formula, but with a correction for proper Caesar
cipher implementation. The formula shifts each character forward in the alphabet by the
specified number of positions.

ii. Decryption Function


The decryption function reverses the encryption process by shifting characters backward in the
alphabet. It uses the modified hint formula to ensure proper decryption.

Key Features of the Program:

1. Case Preservation: Maintains the original case (uppercase/lowercase) of input text


2. Non-alphabetic Characters: Leaves numbers, punctuation, and spaces unchanged
3. Input Validation: Handles invalid shift values and normalizes them to 0-25 range
4. Interactive Interface: Provides a user-friendly menu system for encryption/decryption
5. Brute Force Capability: Includes a function to try all possible shift values for cryptanalysis
6. Historical Examples: Demonstrates the cipher with classical examples

Usage Examples:

Encrypting "Hello" with shift 3 produces "Khoor"


Decrypting "Khoor" with shift 3 returns "Hello"
The program handles mixed case and punctuation correctly

The Caesar cipher, while historically significant, is cryptographically weak and easily broken
through frequency analysis or brute force attacks due to its limited key space of only 26
possible shifts.

You might also like