Encryption has been around for at least 2000 years, and one of the simplest ciphers is the Caesar cipher, which involves shifting the alphabet by a number of characters. You can program a Caesar cipher in 1 line of code and decoding just involves using a negative shift of the same amount. The Caesar was extended with the Vigenère cipher which uses a matrix of Caesar ciphers and a key to determine which cipher to use. One ancient possible cipher appears in the Voynich manuscript and dates back to the 15th century and still never been broken, it is unknown what language the book was written in but it appears as though it may never be broken as all attempts so far have failed.
Prior to World War 2, the Germans developed the Enigma machine which was used extensively to communicate orders in secret, it had multiple rotors and a plug board, the first rotor would rotate every key press, and then after a certain number of rotations it would rotate the next rotor. So this meant if you press AAA it could be encoded as DOG, so each time the same value is encoded it can be a different value, in addition to the rotors the plug board could be used to swap a pair of keys around. The initial position of the rotors and the layout of the plug board was changed daily, and that formed the key that was used each day. The Enigma machines had trillions of possible layouts, but a brilliant British scientist developed the first computer to help crack the possible codes using Bayesian statistics to determine whether the code had been cracked. It was developed at Bletchley Part and was ultra top secret for many years after the war ended (Churchill even ordered the destruction of the computers).
Modern cryptography works very differently than even the Enigma, it works using public and private keys, so you can publish your public key and other people can send you messages but only you can read them, this makes it possible to be able to encode a message but not to be able to decode a message. There is also cyptographic signing, which means you encode your message using your private key, and someone can decode it with the public key, so you can confirm that you sent the message, and by using a combination of both, you can send a message that only you could have sent, and only the receiver could decode.
If you need help writing a program using any of the above cryptographic methods, or even a different one we can help you, in a variety of languages, and we can even write programs that will try and find the key to decode a message (for the simpler cryptographic methods, as the public key remains secure as long as you use a long enough key).