Encrypting helps you hide (scramble) the content of a file by using certain algorithm. It then generates a public and private key which must be put together else the content will not be decrypted.
I will give a simple example on an algorithm using a zip compression software. When you zip a file, what you are sort of doing is using and encrypting software to scramble the content. The zip program has a dictionary of words/combination and replacements. For example every time it sees "EI" (2bytes) for example (recEIve), it replaces EI with 1 or 2 (1 byte) (jdepending on when it finds it). It also looks for word redundancies. See an example i got from how stuff work.
"Ask not what your country can do for you -- ask what you can do for your country."
The quote has 17 words, made up of 61 letters, 16 spaces, one dash and one period. If each letter, space or punctuation mark takes up one unit of memory, we get a total file size of 79 units. To get the file size down, we need to look for redundancies.
Immediately, we notice that:
* "ask" appears two times
* "what" appears two times
* "your" appears two times
* "country" appears two times
* "can" appears two times
* "do" appears two times
* "for" appears two times
* "you" appears two times
it pits these words in a new index and replaces the words with it. so ask (3bytes) become 1(1 byte), same with other words. then your sentence becomes "1 not 2 3 4 5 6 7 8 -- 1 2 8 5 6 7 3 4".
I bring zip up to make you understand the power of algorithms and index creation. A similar process goes on with encryption. So zip generally works by pattern recognition and word replacement. See http://computer.howstuffworks.com/file-compression2.htm for the full gist.
Encryption as you might have guessed works in a similar way but unlike a zip file, the dictionary is pre-defined. Eg. A=C, B=D, C=E you get). Unlike zip file which carry the dictionary along with the zip for re-construction, the encrypted file is sent without the dictionary. The receiver has the exact dictionary (a private key) and reconstructs the message when it arives. the key is usually more complex than that. with 128 bit encryption, each character is represented by a combination of 16 characters (i think) A=BCDE.... We need to confirm that though. When you encrypt a message, you build the private key on the fly so that it is different from another private key. Then you run your message through it and patterns are replaced. That is the general idea. I am sure you are wondering how you the key is sent. I suggest some more research. I also did not talk about the public key part of the equation. Still some more research.
I hope this helps.