Most of the counterfeit medicines are manufactured in non good manufacturing practices (GMP) conditions by uncontrolled or street laboratories. Their chemical composition and purity of raw materials may, therefore, change in the course of time. The public health problem of counterfeit drugs is mostly due to this qualitative and quantitative variability in their formulation and impurity profiles.In this study, impurity profiles were treated like fingerprints representing the quality of the samples. A total of 73 samples of counterfeit and imitations of Viagra ® and 44 samples of counterfeit and imitations of Cialis ® were analysed on a HPLC-UV system. A clear distinction has been obtained between genuine and illegal tablets by the mean of a discriminant partial least squares analysis of the log transformed chromatograms. Following exploratory analysis of the data, two classification algorithms were applied and compared. In our study, the knearest neighbour classifier offered the best performance in terms of correct classification rate obtained with cross-validation and during external validation. For Viagra ® , both crossvalidation and external validation sets returned a 100% correct classification rate. For Cialis ® 92.3% and 100% correct classification rates were obtained from cross-validation and external validation, respectively.