Added error correcting function and fixed decrypt.