I'm not sure about period-related cravings but normal and pregnancy related cravings are based on your body demanding foods it thinks are high in nutrients it needs. Normally that works OK, but if you exclusively eat junk food it will make the best of a bad thing and demand whatever is the most suitable even if that gives you a ridiculous surplus of something else (eg energy). Also, when demanding food the body can be fooled by flavourings (such as craving MSG-coated carbs instead of the protein it actually needs), and measuring your needs can be disrilupted by drugs  (such as alcohol causing white fat cells to absorb more fatty acids, dropping levels in the blood and so triggering a craving for greasy food).