Base encode and decode for packets