One who is lost in the desert or wilderness and has lost track of days, when does he keep Shabbos?
One who has become lost in the wilderness or desert and has lost track of the days of the week is to count 7 days starting from the day which he lost track of Shabbos on, and sanctify Shabbos on that seventh day.
What is he to do on his seventh day: On the seventh day of one’s count he is to say Kiddush and Havdala, and follow all the laws of Shabbos, including both the Biblical and Rabbinical laws. However it is permitted for him to continue traveling even many miles on his seventh day in order to enable him to leave the desert as soon as possible.
Not to do work on the other days: On all the other six days prior to one’s scheduled seventh day, if one has food to eat it is forbidden for him to transgress any Biblical Shabbos prohibition, being that perhaps that day is in truth Shabbos. However one is allowed to transgress Rabbinical Shabbos prohibitions.
Doing work to obtain food to eat: After ones food has run out he may work each day, including his seventh day, so that he obtain enough food to eat for that day, even if doing so involves transgressing Biblical prohibitions. However one may only perform prohibited work in order to obtain the minimum food he needs to survive that day and may thus not work for the next day’s food. This applies even against working on his sixth day for the food of his seventh day. Accordingly if one has enough bread to eat for that day he may not cook any food that day.
If one knows how many days he has been traveling for but lost track of when he left? If one knows he has been traveling for a certain amount of days but is unsure the day he left, then on his eighth day he may do all weekday work, as for certain he did not leave on Shabbos and thus his eighth day must be a weekday. Similarly every eighth day from when he left is a weekday and he may thus do all forms of work on that day.
If one has been captured and no longer has track of which day is Shabbos what is he to do?
He is to follow the same laws as one who is lost in the desert.
Is one to wear Tefillin on his seventh day?
Yes, although not while Davening the Shabbos prayer. [Others however rule that one is not to don Tefillin even during his supposed weekdays, due to possibility that it is Shabbos. We do not rule like this opinion.]
If one of the days is for certain a weekday, as explained above, then if he is able to work enough on this day to supply food for all the other days must he do so?
 Literally “from the day where he became conscious of his forgetfulness”. Meaning if he knows he was in the desert for at least seven days and he remembers losing track of the days three days ago then he begins counting from three days back as day one, and the seventh day from that counting is sanctified. [Mishneh Berurah 344/2 in name of Bach]
 This is Rabbinically required in order to prevent one from forgetting the existence of the sanctity of Shabbos which surpasses the other days of the week. [ibid]
 As although Safek Derabanan Lekula, nonetheless this seventh day of his counting was considered by the Sages like the second day of Yom Tov celebrated in the Diaspora which is likewise forbidden in even Rabbinical prohibitions. [ibid]
 And by a Biblical doubt one is to be stringent.
 As Safek Derabanan Lekula.
 As this is a matter of life and death.
 As perhaps really the sixth day is Shabbos and the seventh is Sunday.
 As he is no longer in a life threatening situation. [Admur]
 M”B 344/1
 M”B 344 in Biur Halacha “Afilu”
 As one follows majority of the days which are weekdays, and although Shabbos is Kavua, nevertheless since there is a Biblical doubt one must be stringent.
 Zichron Yitzchak 31
 As wearing Tefillin on Shabbos transgresses a Biblical command, and it is better to transgress a Biblical command through Sheiv Veal Taseh than through Kum Veasei. [ibid] However Tzaruch Iyun Gadol on this opinion as to avoid this problem one is simply to don the Tefillin with a stipulation “If it is Shabbos then I am wearing it as a clothing, if it is weekday I am wearing it for its Mitzvah” as is ruled in 31/2 regarding Chol Hamoed.
 As explained in the previous footnote.
 M”B 344/11