High blood sugars do cause brain fog, but the Keto diet was originated about 100 years ago to help children with epilepsy. The understanding is that the brain runs better on ketones than sugar. I first did strict Keto before diabetes to lose weight, very successfully, the clarity of thought was amazing.