Cyber Security | ISC Computer Science 2027 Practical

A cyber-security application analyzes messages to identify possible phishing attempts.

Accept a message terminated by ‘.’, ‘?’ or ‘!’ only. The message may contain only alphabets and single blank spaces between words. The program should be case-insensitive.

Display INVALID INPUT if:

  • The message is not terminated by ‘.’, ‘?’ or ‘!’.
  • Any digit or special character (except the terminating punctuation) is present.

The following words are considered phishing keywords:
ACCOUNT, VERIFY, PASSWORD, LOGIN, BANK, URGENT.

Perform the following tasks:

  1. Extract and display all the words of the message in uppercase.
  2. Display:
    i. Total number of words.
    ii. Number of phishing keywords present.
  3. Determine whether the message is either one of the following:
    i. SAFE (no phishing keywords)
    ii. SUSPICIOUS (1 to 2 phishing keywords)
    iii. PHISHING ALERT (more than 2 phishing keywords)
  4. Create an encrypted message as follows:
    i. Reverse every phishing keyword.
    ii. Leave all other words unchanged.

Test your program with the following data and some random data:

Example 1
INPUT:
Verify your account password immediately!
OUTPUT:
WORDS:
VERIFY YOUR ACCOUNT PASSWORD IMMEDIATELY
TOTAL WORDS: 5
PHISHING WORDS: 3
CLASSIFICATION: PHISHING ALERT
ENCRYPTED MESSAGE:
YFIREV YOUR TNUOCCA DROWSSAP IMMEDIATELY

Example 2
INPUT:
Please login to your bank account.
OUTPUT:
WORDS:
PLEASE LOGIN TO YOUR BANK ACCOUNT
TOTAL WORDS: 6
PHISHING WORDS: 3
CLASSIFICATION: PHISHING ALERT
ENCRYPTED MESSAGE:
PLEASE NIGOL TO YOUR KNAB TNUOCCA

Example 3
INPUT:
Study hard and achieve success!
OUTPUT:
WORDS:
STUDY HARD AND ACHIEVE SUCCESS
TOTAL WORDS: 5
PHISHING WORDS: 0
CLASSIFICATION: SAFE
ENCRYPTED MESSAGE:
STUDY HARD AND ACHIEVE SUCCESS

Example 4
INPUT:
Verify account123 now!
OUTPUT:
INVALID INPUT

import java.util.Scanner;
class CyberSecurity{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.print("INPUT: ");
        String s = in.nextLine().toUpperCase();
        if(s.length() == 0){
            System.out.println("INVALID INPUT");
            return;
        }
        char last = s.charAt(s.length() - 1);
        if(".?!".indexOf(last) == -1){
            System.out.println("INVALID INPUT");
            return;
        }
        for(int i = 0; i < s.length() - 1; i++){
            char ch = s.charAt(i);
            if(!Character.isLetter(ch) && ch != ' '){
                System.out.println("INVALID INPUT");
                return;
            }
        }
        String keywords[] = {"ACCOUNT", "VERIFY", "PASSWORD", "LOGIN", "BANK", "URGENT"};
        String word = "";
        int count = 0;
        int phishing = 0;
        String encrypt = "";
        for(int i = 0; i < s.length(); i++){
            char ch = s.charAt(i);
            if(Character.isLetter(ch))
                word += ch;
            else{
                boolean isPhishing = false;
                System.out.print(word + " ");
                count++;
                for(int j = 0; j < keywords.length; j++){
                    if(word.equals(keywords[j])){
                        phishing++;
                        isPhishing = true;
                        break;
                    }
                }
                if(isPhishing)
                    encrypt += reverse(word) + " ";
                else
                    encrypt += word + " ";
                word = "";
            }
        }
        System.out.println("\nTOTAL WORDS: " + count);
        System.out.println("PHISHING WORDS: " + phishing);
        System.out.print("CLASSIFICATION: ");
        if(phishing == 0)
            System.out.println("SAFE");
        else if(phishing < 3)
            System.out.println("SUSPICIOUS");
        else
            System.out.println("PHISHING ALERT");
        System.out.println("ENCRYPTED MESSAGE:");
        System.out.println(encrypt);
    }
    public static String reverse(String w){
        String r = "";
        for(int i = w.length() - 1; i >= 0; i--)
            r += w.charAt(i);
        return r;
    }
}