What is the purpose of encrypting something? To change data that can only be changed back with they key it was encrypted with.
Therefore an encryption algorithm modifies data from a key.
A [very] basic encryption algorithm might read some data, and a number (say 10) to it and then move on the the next chunk of data. This would be a very easy encryption to crack but it is an example.
Another form of encryption is an XOR encryption. If your familiar with modifying data on the bit level you will know that XOR'ing two numbers will result in a different number. An encryption algorithm might use this.
Say it expected a key which was 10 bytes long. The encryption algorithm might read a byte of data, XOR it with the first byte of the key. Then it would XOR the next byte with the next byte in the key. I could keep doing this and when reaching the 10th byte, start XOR'ing with the first byte of the key again.
An even more advanced encryption algorithm might not XOR the first byte of the data with the first byte of the key, it might use XOR the data byte with the last key byte and then the second data byte with the second-to-last key byte and so on. It might even use every second byte from the key until the end then use the bytes it skipped, making it harder to crack.
Decryption would be just as easy as encrypting it, so long as you have the key, just instead of XOR'ing the data.
I wrote a simple C++ program that encrypts a byte and then decrypts it using the XOR method.
#include
using namespace std;
int main()
{
int dataByte = 12;
int keyByte = 65;
int encrypted = dataByte ^ keyByte;
cout << "Data byte: " << dataByte << "\n";
cout << "Key Byte: " << keyByte << "\n";
cout << "\n";
cout << "XOR'ing the data byte with the key byte results in excrypted data\n";
cout << dataByte << " ^ " << keyByte << " = " << encrypted << "\n";
cout << "XOR'ing the key byte with the encrypted byte decrypts the byte\n";
cout << keyByte << " ^ " << encrypted << " = " << (keyByte ^ encrypted) << "\n";
return 0;
}