A Secure Lightweight SMS Spam Detection Framework with Robustness to Text Obfuscation Attacks
Abstract
1. Introduction
- As the results could have been skewed toward the greater class because of the imbalanced dataset, oversampling approaches were employed;
- Using TF-IDF, bag-of-words, and N-gram techniques created rich, weighted feature sets to feed into machine learning models, enhancing their capacity to differentiate between spam and non-spam messages;
- We applied PCA to significantly reduce the feature space extracted by TF-IDF, BoW, and N-gram methods, resulting in a compact model without sacrificing accuracy.
- The combination of TF-IDF feature extraction and PCA enhanced the model’s discriminative ability while reducing overfitting, and integrating optimized features with a Decision Tree classifier yielded remarkable performance;
- We assessed our model’s robustness to typical adversarial text disturbances, proving it can continue to operate at a high level even when spam attempts are masked.
2. Related Works
3. Proposed Methods
3.1. Dataset Collection Phase
3.2. Pre-Processing Phase
3.2.1. Data Cleaning
3.2.2. Tokenization
3.3. Feature Extraction Phase
3.3.1. Bag of Words (BoW)
| Algorithm 1: Bag-of-Words (BoW) Feature Extraction |
| Input: Pre-processed text documents D = {d1,d2,…,dn}. Output: Bag-of-Words feature matrix B. Begin For 1. Import the pre-processed text. 2. Vocabulary Development: 2.1 Construct an individual corpus out of all the documents. 2.2 To build vocabulary V = {v1,v2,…,vm}, one must take special terms out of the corpus. 3. Initialize the Feature Matrix: 3.1 Construct an n × m matrix. 3.2 Set all the matrix’s elements to zero. 4. Generate BoW Features: 4.1 For each document di in D: 4.1.1 For each word w in di: a. Find the index j of w in the vocabulary V. b. Increment B(i,j) by 1. 5. Construct the Final Representation: 5.1 Each row of B represents a document. 5.2 Each column of B represents a vocabulary term. 5.3 Each matrix value indicates the frequency of a term in a document. End for 6. Return the Bag-of-Words feature matrix B. End |
3.3.2. Term Frequency–Inverse Document Frequency (TF-IDF)
| Algorithm 2: TF-IDF Feature Extraction |
| Input: Pre-processed Text D = {d1, d2,…,dn}. Output: TF-IDF feature matrix F. Begin For 1. Import the pre-processed text. 2. Construct the vocabulary set V from all unique terms in the dataset. 3. For each document d∈D, perform the following steps: 3.1 Calculate the Term Frequency (TF) for each term t in document d: TF(t,d) = Number of times term t appears in document d/Total number of terms in document d 3.2 Calculate Document Frequency (DF) for each term t in document d: Count the number of documents containing term t. 3.3 Calculate Inverse Document Frequency (IDF) using the formula: I(t,D) = log (Total number of documents in d/Number of documents with term t in d) 3.4 Combine TF and IDF to calculate the final TF-IDF using the formula: TF-IDF(t,d,D) = TF(t,d) × IDF(t,D) 3.5 Represent document d as a numerical feature vector using the TF-IDF weights of all terms in V. 4. Construct the document-term matrix F, where 4.1 Show every document as a vector, with each dimension representing the TF-IDF score of a phrase. 4.2 A document-term matrix is the end product, where words are represented by columns and documents by rows. End for 5. Return the set of TF-IDF feature matrix F. End |
3.3.3. N-Gram
| Algorithm 3: N-gram Feature Extraction |
| Input: Pre-processed Text D = {d1, d2,…,dn} Output: Numerical Feature Vector F. Begin For 1. Import the pre-processed and tokenized text documents. 2. Initialize: NGram_List ← empty list Vocabulary ← empty set 3. For each document d ∈ D do 3.1 Generate N-grams using a sliding window approach. 3.2 For each generated N-gram g do 3.2.1 Add g to NGram_List. 3.2.2 Update the frequency count of g. 3.3 Store all extracted N-grams for document d. End For 4. Vocabulary Construction: 4.1 Combine all extracted N-grams from all documents. 4.2 Extract unique N-grams to form the vocabulary V. 5. Feature Representation: 5.1 For each document d ∈ D do 5.1.1 Count the occurrences of each N-gram in V. 5.1.2 Represent d as a numerical feature vector. End for 5.2 Store all feature vectors in F. 6. Return the set of N-gram feature vectors F. End |
3.4. Feature Selection Phase
| Algorithm 4: PCA-Based Feature Selection |
| Input: Feature vector F = {f1, f2, …, fn} Number of principal components k |
| Output: Reduced feature set Y |
| Begin |
| 1. Normalize the Data: Standardize each feature using: Z = (X − μ)/σ 2. Compute the Covariance Matrix using: C = (1/(n − 1)) × ZTZ 3. Compute Eigenvalues and Eigenvectors using Cv = λv 4. Sort eigenvalues and corresponding eigenvectors: λ1 > λ2 > λ3 >...> λm 5. Form the projection matrix: P = [v1,v2,v3,…,vk] 6. Project data onto the reduced feature space: Y = ZP 7. Obtain Reduced Features: Y represents the reduced-dimensional feature set. End |
3.5. Classification Phase
3.5.1. Logistic (LogReg)
3.5.2. Decision Tree (DT)
4. Experimental Setup
4.1. Experimental Environment
4.2. Dataset
4.3. Evaluation Parameters
4.4. Validation Strategy
5. Results and Discussion
5.1. Compact and Efficient Design Analysis
5.2. Robustness Against Adversarial Text Perturbations
5.3. Additional Evaluation Results
5.4. Comparison
6. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Abid, M.A.; Ullah, S.; Siddique, M.A.; Mushtaq, M.F.; Aljedaani, W.; Rustam, F. Spam SMS filtering based on text features and supervised machine learning techniques. Multimed. Tools Appl. 2022, 81, 39853–39871. [Google Scholar] [CrossRef]
- Abayomi-Alli, O.; Misra, S.; Abayomi-Alli, A. A deep learning method for automatic SMS spam classification: Performance of learning algorithms on indigenous dataset. Concurr. Comput. Pract. Exp. 2022, 34, e6989. [Google Scholar] [CrossRef]
- Durlik, I.; Miller, T.; Kostecka, E.; Zwierzewicz, Z.; Łobodzińska, A. Cybersecurity in autonomous vehicles—Are we ready for the challenge? Electronics 2024, 13, 2654. [Google Scholar] [CrossRef]
- Jasim, A.A.; Ali Alheeti, K.M. The role of intrusion detection systems and machine in protecting industrial control systems ICS environments. In AIP Conference Proceedings; AIP Publishing: Melville, NY, USA, 2024; Volume 3207. [Google Scholar]
- Ali, N.J.; Hamzah, N.A.; Radhi, A.D.; Niu, Y.; JosephNg, P.S.; Tawfeq, J.F. 5G-backed resilience and quality enhancement in internet of medical things infrastructure for resilient infrastructure. TELKOM-NIKA (Telecommun. Comput. Electron. Control) 2024, 22, 372–379. [Google Scholar] [CrossRef]
- Hama, D.K.; Mubarek, F.S.; Abdullatif, F.A. Enhanced Security Taxonomy for Fog-Enabled VANETs: A Comprehensive Survey on Attacks, Challenges, Applications and Architectures. Passer J. Basic Appl. Sci. 2025, 7, 37–61. [Google Scholar]
- Johari, M.F.; Chiew, K.L.; Hosen, A.R.; Yong, K.S.; Khan, A.S.; Abbasi, I.A.; Grzonka, D. Key insights into recommended SMS spam detection datasets. Sci. Rep. 2025, 15, 8162. [Google Scholar] [CrossRef] [PubMed]
- Baaqeel, H.; Zagrouba, R. Hybrid SMS spam filtering system using machine learning techniques. In Proceedings of the 2020 21st International Arab Conference on Information Technology (ACIT); IEEE: New York, NY, USA, 2020; pp. 1–8. [Google Scholar]
- Chrismanto, A.R.; Sari, A.K.; Suyanto, Y. Enhancing spam comment detection on social media with emoji feature and post-comment pairs approach using ensemble methods of machine learning. IEEE Access 2023, 11, 80246–80265. [Google Scholar] [CrossRef]
- Kim, S.N.; Baldwin, T.; Kan, M.-Y. An unsupervised approach to domain-specific term extraction. In Proceedings of the Australasian Language Technology Association Workshop 2009, Sydney, Australia, 3–4 December 2009; p. 94. [Google Scholar]
- Angeli, A.; Filliat, D.; Doncieux, S.; Meyer, J.-A. Fast and incremental method for loop-closure detection using bags of visual words. IEEE Trans. Robot. 2008, 24, 1027–1037. [Google Scholar] [CrossRef]
- Nagwani, N.K. A Bi-Level Text Classification Approach for SMS Spam Filtering and Identifying Priority Messages. Int. Arab. J. Inf. Technol. 2017, 14, 61–68. [Google Scholar]
- Ahmed, I.T.; Der, C.S.; Hammad, B.T. Recent Approaches on No-Reference Image Quality Assessment for Contrast Distortion Images with Multiscale Geometric Analysis Transforms: A Survey. J. Theor. Appl. Inf. Technol. 2017, 95, 561–569. [Google Scholar]
- Safie, W.; Sjarif, N.N.A.; Azmi, N.F.M.; Yuhaniz, S.S.; Mohd, R.C.; Yusof, S.Y. Sms spam classification using vector space model and artificial neural network. Int. J. Adv. Soft Compu. Appl. 2018, 10, 130–140. [Google Scholar]
- de Luna, R.G.; Magnaye, V.C.; Reaño, R.A.L.; Enriquez, K.L.; Astorga, D.; Celestial, T.; Española, A.M.; Lanting, B.A.; Mugar, D.; Ramos, M. A Machine Learning Approach for Efficient Spam Detection in Short Messaging System (SMS). In Proceedings of the TENCON 2023-2023 IEEE Region 10 Conference (TENCON); IEEE: New York, NY, USA, 2023; pp. 53–58. [Google Scholar]
- Oyeyemi, D.A.; Ojo, A.K. SMS Spam Detection and Classification to Combat Abuse in Telephone Networks Using Natural Language Processing. arXiv 2024, arXiv:2406.06578. [Google Scholar]
- Ballı, S.; Karasoy, O. Development of content-based SMS classification application by using Word2Vec-based feature extraction. IET Softw. 2019, 13, 295–304. [Google Scholar] [CrossRef]
- Saeed, V.A. A Method for SMS Spam Message Detection Using Machine Learning. Artif. Intell. Robot. Dev. J. 2023, 3, 214–228. [Google Scholar] [CrossRef]
- Das Gupta, S.; Saha, S.; Das, S.K. SMS spam detection using machine learning. J. Phys. Conf. Ser. 2021, 1797, 12017. [Google Scholar] [CrossRef]
- Dharrao, D.; Gaikwad, P.; Gawai, S.V.; Bongale, A.M.; Patel, K.; Singh, A. Classifying SMS as Spam or Ham: Leveraging NLP and Machine Learning Techniques. Int. J. Saf. Secur. Eng. 2024, 14, 289–296. [Google Scholar] [CrossRef]
- Ahmadi, M.; Khajavi, M.; Varmaghani, A.; Ala, A.; Danesh, K.; Javaheri, D. Leveraging Large Language Models for Cybersecurity: Enhancing SMS Spam Detection with Robust and Context-Aware Text Classification. arXiv 2025, arXiv:2502.11014. [Google Scholar]
- Taylor, A.; Robert, A. Using Machine Learning to Detect Fraudulent SMSs in Chichewa. arXiv 2025, arXiv:2502.16947. [Google Scholar]
- Ahmed, I.T.; Der, C.S.; Jamil, N.; Hammad, B.T. Analysis of Probability Density Functions in Existing No-Reference Image Quality Assessment Algorithm for Contrast-Distorted Images. In Proceedings of the 2019 IEEE 10th Control and System Graduate Research Colloquium (ICSGRC); IEEE: New York, NY, USA, 2019; pp. 133–137. [Google Scholar]
- Robertson, S. Understanding inverse document frequency: On theoretical arguments for IDF. J. Doc. 2004, 60, 503–520. [Google Scholar] [CrossRef]
- Omuya, E.O.; Okeyo, G.O.; Kimwele, M.W. Feature selection for classification using principal component analysis and information gain. Expert Syst. Appl. 2021, 174, 114765. [Google Scholar] [CrossRef]
- Wang, S.; Yu, X.; Jia, W. A new population initialization of particle swarm optimization method based on pca for feature selection. J. Big Data 2021, 3, 1–9. [Google Scholar] [CrossRef]
- Jayapandian, N. Machine Learning Based Spam E-Mail Detection Using Logistic Regression Algorithm. In Proceedings of the 2023 IEEE International Conference on ICT in Business Industry & Government (ICTBIG); IEEE: New York, NY, USA, 2023; pp. 1–6. [Google Scholar]
- Priyanka; Kumar, D. Decision tree classifier: A detailed survey. Int. J. Inf. Decis. Sci. 2020, 12, 246–269. [Google Scholar] [CrossRef]
- Kaggle. Sms Spam Collection Dataset. 2016. Available online: https://www.kaggle.com/datasets/uciml/sms-spam-collection-dataset (accessed on 1 January 2026).
- SMS Spam Collection. Available online: https://archive.ics.uci.edu/dataset/228/sms+spam+collection (accessed on 1 January 2026).
- Ahmed, I.T.; Hammad, B.T.; Jamil, N. A comparative analysis of image copy-move forgery detection algorithms based on hand and machine-crafted features. Indones. J. Electr. Eng. Comput. Sci. 2021, 22, 1177–1190. [Google Scholar] [CrossRef]
- Heckler, C.E. Applied Multivariate Statistical Analysis; Prentice Hall: Saddle River, NJ, USA, 2005; p. 517. [Google Scholar]
- Ahmed, I.T.; Der, C.S.; Hammad, B.T.; Jamil, N. Contrast-distorted image quality assessment based on curvelet domain features. Int. J. Electr. Comput. Eng. 2021, 11, 2595–2603. [Google Scholar] [CrossRef]
- Sjarif, N.N.A.; Azmi, N.F.M.; Chuprat, S.; Sarkan, H.M.; Yahya, Y.; Sam, S.M. SMS spam message detection using term frequency-inverse document frequency and random forest algorithm. Procedia Comput. Sci. 2019, 161, 509–515. [Google Scholar] [CrossRef]
- Xia, T.; Chen, X. A weighted feature enhanced Hidden Markov Model for spam SMS filtering. Neurocomputing 2021, 444, 48–58. [Google Scholar] [CrossRef]
- Szabó Nagy, K.; Kapusta, J. Twidw—A novel method for feature extraction from unstructured texts. Appl. Sci. 2023, 13, 6438. [Google Scholar] [CrossRef]
- Subhalakshmi, R.T. SMS Spam Detection using Machine Learning. J. Sci. Technol. Res. (JSTAR) 2025, 6, 1. [Google Scholar] [CrossRef]









| Year/Ref. | Feature Extraction Method | Classification Methods | Accuracy (%) | Dataset | Limitations |
|---|---|---|---|---|---|
| 2019, [17] | Word2Vec | Random Forest (RF) | 99.64 | UCI | Limits of the model generalizability |
| 2020, [8] | Word Tokenization | SVM | 98.8 | UCI | Limit adaptability and scalability due to manual pre-processing used |
| 2021, [19] | TF-IDF | Naive Bayes (NB) | 96.5 | Spam Assassin | Limits to independence assumption inherent in the Naive Bayes algorithm |
| 2022, [2] | Word2Vec | Long Short-Term Memory (LSTM) | 98.6 | Indigenous | Limits of the model scalability and transferability |
| 2022, [1] | TF-IDF and bag-of-words | SVM, RF, NB, and Logistic Regression | 99 | UCI | Weak contextual comprehension |
| 2023, [18] | Word Embedding | J48, KNN, and DT | 98.40 | UCI | Limits the generalizability of the model |
| 2023, [15] | Bag-of-Words | Bernoulli NB | 96.63 | Self-Acquired SMS Messages | Limit of cross-dataset evaluation |
| 2024, [16] | Contextual Sentence Embedding | NB and BERT | 97.3 | Kaggle’s and DSN | Limits of the model generality |
| 2024, [20] | TF-IDF | SVM, NB, RF, Logistic Regression | 97.31 | UCI | Limits the generalizability of the model |
| 2025, [22] | TF-IDF | RF and Logistic Regression | 97 | Chichewa | Limits the generalizability of the model |
| 2025, [21] | Bag-of-Words and TF-IDF | NB, KNN, SVM, DT, LDA | 96.2 | UCI | Performance of a biased classifier |
| Metric | Description | Formula | Equation No. |
|---|---|---|---|
| Accuracy | It represents the proportion of accurately recognized items to all items entered. | (2) | |
| Precision | The percent of all given images that the classification algorithm properly identified is represented by this number. | (3) | |
| Error | This is the proportion of every image to the overall number of images that have been mislabelled. | (4) | |
| Recall | It represents the proportion of all images belonging to that category that have been accurately classified. | (5) | |
| F1-Score | A common way to think of the F1-score is to consider it a weighted average of recall and precision. | (6) |
| Classifier | Feature Extracted Dimension | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| BoW_7275 Features | TF-IDF_7275 Features | N-Gram_27369 Features | |||||||||||||
| Evaluation Measures (%) | Evaluation Measures (%) | Evaluation Measures (%) | |||||||||||||
| Accuracy | Error | F1-Score | Precision | Recall | Accuracy | Error | F1-Score | Precision | Recall | Accuracy | Error | F1-Score | Precision | Recall | |
| DT | 97 | 3 | 97 | 96 | 100 | 99 | 1 | 99 | 99 | 99 | 97 | 3 | 89 | 94 | 84 |
| Log | 95 | 5 | 95 | 98 | 92 | 98 | 2 | 98 | 96 | 100 | 90 | 10 | 94 | 100 | 90 |
| Classifier | Feature Extracted Dimension | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| BoW_PCA_1248 Features | TF-IDF_PCA_1976 Features | N-Gram_PCA_2702 Features | |||||||||||||
| Evaluation Measures (%) | Evaluation Measures (%) | Evaluation Measures (%) | |||||||||||||
| Accuracy | Error | F1-Score | Precision | Recall | Accuracy | Error | F1-Score | Precision | Recall | Accuracy | Error | F1-Score | Precision | Recall | |
| DT | 98 | 2 | 98 | 97 | 100 | 99 | 1 | 99 | 98 | 100 | 97 | 3 | 97 | 96 | 100 |
| Log | 96 | 4 | 96 | 99 | 94 | 98 | 2 | 98 | 99 | 97 | 93 | 7 | 93 | 99 | 87 |
| Property | Without PCA | With PCA |
|---|---|---|
| Model size (MB) | 18.5 | 4.2 |
| Inference Time (ms/message) | 8.4 | 2.1 |
| Measure (%) | Clean Data | Adversarial Data |
|---|---|---|
| Accuracy | 99 | 96.5 |
| Precision | 99 | 95 |
| Recall | 99 | 96 |
| F1-Score | 99 | 95.5 |
| Measure (%) | Kaggle Dataset |
|---|---|
| Accuracy | 95.2 |
| Precision | 94 |
| Recall | 96 |
| F1-Score | 95 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.
Share and Cite
Hammad, B.T.; Ahmed, I.T.; Hafez, M.A.; Voon, B.W.N. A Secure Lightweight SMS Spam Detection Framework with Robustness to Text Obfuscation Attacks. Computers 2026, 15, 451. https://doi.org/10.3390/computers15070451
Hammad BT, Ahmed IT, Hafez MA, Voon BWN. A Secure Lightweight SMS Spam Detection Framework with Robustness to Text Obfuscation Attacks. Computers. 2026; 15(7):451. https://doi.org/10.3390/computers15070451
Chicago/Turabian StyleHammad, Baraa Tareq, Ismail Taha Ahmed, Mohamed A. Hafez, and Betty Wan Niu Voon. 2026. "A Secure Lightweight SMS Spam Detection Framework with Robustness to Text Obfuscation Attacks" Computers 15, no. 7: 451. https://doi.org/10.3390/computers15070451
APA StyleHammad, B. T., Ahmed, I. T., Hafez, M. A., & Voon, B. W. N. (2026). A Secure Lightweight SMS Spam Detection Framework with Robustness to Text Obfuscation Attacks. Computers, 15(7), 451. https://doi.org/10.3390/computers15070451

