Statistical Mechanics Approach to Coding Theory