Computer security is of great concern to users and corporate bodies now ever than before due to activities of criminals and hackers on the Internet. Software piracy and the breach of the copyright laws, intentionally or unintentionally is very common these days. Software piracy is a menace to software developers and computer users all over the world. Software hackers have become nuisance to many organizations, corporate bodies and government alike. Pirating software has caused lost of several billions US Dollars and the problem continued unabated. There have been a lot of security threats in recent past due to the activities of hackers. Several financial organizations and national securities have been threatened and even some have been compromised. In this paper, we proposed the code encryption technique for combating software piracy. Using C++ programming language to develop the code, the technique converts plain code to an encrypted form that cannot be understood by the hacker or intended hacker unless he has the key to encrypt or decode the encrypted data. Our result shows that using this technique, it will be difficult to pirate software after it has been released to intended user(s)..