rename MAX_DATALEN to BLOCKLEN

This also fixes an error when reading the encrypted value from memory
fix conditional in while loop
more and improved debug output