Technically, Encryption and Compression are two different activities though at times, doing one thing results in another (e.g. encrypting audio in certain form also compresses it). I suppose you want to just compress the file. What you are trying to do is binary compression. It does not necessarily mean that all compression is done only at binary level. Depending upon the data that you are trying to compress, the algorithms may change. It is best to know at least popular data compression algorithms beforehand so that you can code on your own.
huffman coding is one of the best methods for compressing a file. What you basically do is to check occurence frequencies of letters, groups of letters, or words (whatever your level of requirement is) and assign a number to it. For example the most frequent element will be assigned to the number that can be representable with the least number of bits and the least freuqent the most. However huffman requires the mapping table stored as well. Gaussian encoding is another compression scheme that does not require global knowledge.
Also you may have other requirements, such as being able to uncompress a substring without uncompressing everything. So, theres a lot for compression actually
The book "Managing Gigabytes" is an excellent resource for compression, gives a comprehensive explanation to all these algorithms if you have access to it