Practical PapersISCClass 12Computer Science

ISC Practical 2027: Phishing Message Detector and Encryption – Algorithm and Java Program

Fully solved ISC Computer Science Practical 2027 string question: validate a sentence, extract words, count phishing keywords, classify the message as SAFE, SUSPICIOUS or PHISHING ALERT and encrypt it by reversing the keywords.

7 min read
ISC Practical 2027: Phishing Message Detector and Encryption – Algorithm and Java Program

This is Question 1 of Sample Paper 2 from the specimen questions CISCE has released for the ISC Year 2027 Computer Science Practical (Paper 2). The concept area is String manipulation and encryption. Below you will find the question, a plain-language explanation of the logic, an exam-ready algorithm, a fully documented Java program, the real output for every sample input, and tips for scoring the full 15 marks.

Every program on this page was compiled with JDK 21 and run on CISCE’s sample inputs, plus extra boundary inputs of the kind a visiting examiner will try.

The question

A cyber-security application analyses 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 '!', or if any digit or special character (other than the terminating punctuation) is present.

The phishing keywords are: ACCOUNT, VERIFY, PASSWORD, LOGIN, BANK, URGENT. Perform the following tasks:

  1. Extract and display all the words of the message in uppercase.
  2. Display the total number of words and the number of phishing keywords present.
  3. Classify the message as SAFE (no keywords), SUSPICIOUS (1 or 2 keywords) or PHISHING ALERT (more than 2 keywords).
  4. Create an encrypted message by reversing every phishing keyword and leaving all other words unchanged.

CISCE gives 4 examples with this question. Each one is shown with its output in the Output section below, so you can check your own program against it.

Understanding the problem

A string manipulation question in the standard ISC pattern: validate the sentence, split it into words, process each word and rebuild a new sentence.

  • Validation first. Check the last character, then check that the rest contains only letters and spaces, with no leading, trailing or double spaces. "Single blank spaces" is part of the rule, so "Login now." is invalid.
  • Case-insensitive: convert the message to uppercase once, then compare every word with the keyword list using equals().
  • Keep the keywords in an array (static final String KEYS[]). A loop over the array is cleaner than six || conditions, and it is easy to extend.
  • Reverse a word with a loop from the last character to the first. Use StringBuilder.reverse() only if your teacher allows it. Writing the loop shows the logic.
Message words with phishing keywords highlighted and reversed, plus the three classification levels
Question 4: worked example

Algorithm [3 marks]

Write the algorithm in the planning session, in numbered steps like these. It must match your program exactly.

  1. Start.
  2. Input the message msg and trim it.
  3. If the last character is not '.', '?' or '!', print "INVALID INPUT" and stop.
  4. Let body = msg without its last character. If body starts or ends with a space, contains two spaces together, or contains any character that is not a letter or a space, print "INVALID INPUT" and stop.
  5. Convert body to uppercase and split it at spaces into words[]. Set count = number of words.
  6. Set phish = 0. For each word w: if w is one of the six keywords, increase phish and append reverse(w) to enc; otherwise append w to enc.
  7. If phish == 0 the type is SAFE, else if phish ≤ 2 it is SUSPICIOUS, otherwise PHISHING ALERT.
  8. Print the words, count, phish, the type and the encrypted message.
  9. Stop.

Java program [7 marks]

The program uses a class with separate methods for each task and comments that explain every data member and the special logic. That is what the 2 documentation marks are for.

PhishingDetector.java
import java.util.Scanner;

/**
 * ISC Practical 2027 - Sample Paper 2, Question 1
 * Checks a message for phishing keywords, classifies it and
 * encrypts it by reversing every phishing keyword.
 */
public class PhishingDetector
{
    String msg;              // message entered by the user
    String words[];          // words of the message in uppercase
    int count;               // number of words
    static final String KEYS[] = {"ACCOUNT", "VERIFY", "PASSWORD", "LOGIN", "BANK", "URGENT"};

    PhishingDetector(String m)
    {
        msg = m.trim();
    }

    // ends with . ? or ! ; the rest has only letters and single spaces between words
    boolean isValid()
    {
        int len = msg.length();
        if (len < 2)
            return false;
        char last = msg.charAt(len - 1);
        if (last != '.' && last != '?' && last != '!')
            return false;
        String body = msg.substring(0, len - 1);
        if (body.startsWith(" ") || body.endsWith(" ") || body.indexOf("  ") >= 0)
            return false;
        for (int i = 0; i < body.length(); i++)
        {
            char ch = body.charAt(i);
            if (!Character.isLetter(ch) && ch != ' ')
                return false;
        }
        return true;
    }

    // splits the message (without its last character) into uppercase words
    void extractWords()
    {
        String body = msg.substring(0, msg.length() - 1).toUpperCase();
        words = body.split(" ");
        count = words.length;
    }

    boolean isKeyword(String w)
    {
        for (int i = 0; i < KEYS.length; i++)
            if (KEYS[i].equals(w))
                return true;
        return false;
    }

    String reverse(String w)
    {
        String r = "";
        for (int i = w.length() - 1; i >= 0; i--)
            r += w.charAt(i);
        return r;
    }

    void process()
    {
        if (!isValid())
        {
            System.out.println("INVALID INPUT");
            return;
        }
        extractWords();
        int phish = 0;
        String all = "", enc = "";
        for (int i = 0; i < count; i++)
        {
            all += words[i] + " ";
            if (isKeyword(words[i]))
            {
                phish++;
                enc += reverse(words[i]) + " ";
            }
            else
                enc += words[i] + " ";
        }
        String type;
        if (phish == 0)
            type = "SAFE";
        else if (phish <= 2)
            type = "SUSPICIOUS";
        else
            type = "PHISHING ALERT";

        System.out.println("WORDS:");
        System.out.println("    " + all.trim());
        System.out.println("TOTAL WORDS: " + count);
        System.out.println("PHISHING WORDS: " + phish);
        System.out.println("CLASSIFICATION: " + type);
        System.out.println("ENCRYPTED MESSAGE:");
        System.out.println("    " + enc.trim());
    }

    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the message:");
        PhishingDetector ob = new PhishingDetector(sc.nextLine());
        ob.process();
    }
}

Variable description

Variable description
Name           Type       Purpose
-------------  ---------  -------
msg            String     message entered by the user
words[]        String[]   words of the message in uppercase
count          int        total number of words
KEYS[]         String[]   the six phishing keywords
phish          int        number of keywords found
enc            String     encrypted message being built
type           String     SAFE, SUSPICIOUS or PHISHING ALERT

Output [3 marks]

These are the actual outputs of the program above for every example in the question:

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

Test it on unknown inputs

One of the 3 output marks is for correct output on inputs the examiner chooses, usually boundary cases. Our program handles these correctly:

One keyword (SUSPICIOUS)
INPUT:
This is an urgent reminder?

OUTPUT:
WORDS:
    THIS IS AN URGENT REMINDER
TOTAL WORDS: 5
PHISHING WORDS: 1
CLASSIFICATION: SUSPICIOUS
ENCRYPTED MESSAGE:
    THIS IS AN TNEGRU REMINDER
Missing terminating character
INPUT:
Verify your password

OUTPUT:
INVALID INPUT
Two spaces between words
INPUT:
Login  now.

OUTPUT:
INVALID INPUT

How to score full marks on this question

Marks distribution for the ISC Computer Science practical: algorithm 3, program 7, hard copy 2, output 3
ISC Paper 2: how the 15 exam marks are divided
  • Write separate methods isValid(), isKeyword() and reverse(). Small, named methods make the algorithm and documentation marks easy to earn.
  • Test both kinds of invalid input: a missing full stop and a digit inside a word.
  • Count keywords per occurrence: "bank bank bank." has 3 keywords and is a PHISHING ALERT.
  • Keep the typed program identical to the planned one. Large differences between your planning sheet and the printout cost the 2 hard-copy marks.

Common mistakes to avoid

  • Splitting the original message without removing the full stop, so the last word becomes "ACCOUNT." and is not recognised as a keyword.
  • Using contains() on the whole sentence. That finds "BANK" inside "BANKER" and cannot count repeats correctly.
  • Forgetting the SUSPICIOUS band (1 or 2 keywords). None of CISCE’s examples tests it, but an examiner might.

This post is part of our series that solves all 12 specimen questions for the ISC 2027 Computer Science practical, one question a day. Practise writing the algorithm and program on paper in 90 minutes before you type it. That is exactly how the exam works.