Esempio n. 1
0
        /* P A I N T  L I N E */

        /*----------------------------------------------------------------------------
        *       %%Function: PaintLine
        *       %%Qualified: bg.Reporter.PaintLine
        *       %%Contact: rlittle
        *
        *  ----------------------------------------------------------------------------*/
        void PaintLine(Graphics gr, RLD rld, int iLine)
        {
            int iMeal;

            DrawTextInColumn(gr, rld.sDay, m_ptb.fontText, m_ptb.brushText, 0, YFromLine(iLine), 1, HorizontalAlignment.Center);

            for (iMeal = 0; iMeal <= iMealDinner; iMeal++)
            {
                if (rld.mpimd[iMeal].nBefore > 0)
                {
                    DrawTextInColumn(gr, rld.mpimd[iMeal].nBefore.ToString(), m_ptb.fontText, m_ptb.brushText, 1 + iMeal * 3, YFromLine(iLine), 1, HorizontalAlignment.Right);
                }
                if (rld.mpimd[iMeal].nCarbs > 0)
                {
                    DrawTextInColumn(gr, rld.mpimd[iMeal].nCarbs.ToString(), m_ptb.fontText, m_ptb.brushText, 2 + iMeal * 3, YFromLine(iLine), 1, HorizontalAlignment.Center);
                }
                if (rld.mpimd[iMeal].nAfter > 0)
                {
                    DrawTextInColumn(gr, rld.mpimd[iMeal].nAfter.ToString(), m_ptb.fontText, m_ptb.brushText, 3 + iMeal * 3, YFromLine(iLine), 1, HorizontalAlignment.Right);
                }
            }

            DrawTextInColumn(gr, rld.nBedReading.ToString(), m_ptb.fontText, m_ptb.brushText, icolBed, YFromLine(iLine), 1, HorizontalAlignment.Right);
            DrawTextInColumn(gr, /*rld.sDateHeader + "] " + */ rld.sComment, m_ptb.fontText, m_ptb.brushText, icolComments, YFromLine(iLine), 1, HorizontalAlignment.Left);
        }
Esempio n. 2
0
        private void cryptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();

            fd.Title  = "Select a Script...";
            fd.Filter = "All ExHIBIT Scripts File|*.rld";
            if (fd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var Key = new Form2();

            if (Key.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var Script = System.IO.File.ReadAllBytes(fd.FileName);
            var RLDMan = new RLD(Script, Key.Key);

            RLDMan.XOR(ref Script);
            System.IO.File.WriteAllBytes(fd.FileName + ".crypt", Script);
            MessageBox.Show("Done!");
        }
Esempio n. 3
0
        private bool DoubleThreadBruteForce(byte[] Script)
        {
            Thread T1 = new Thread(() =>
            {
                uint[] Key  = new uint[0];
                bool Sucess = RLD.FindKey(Script, out Key);
                if (Sucess)
                {
                    this.Key = Key;
                }
            });

            T1.Start();

            uint Dots = 2;

            while (T1.IsAlive)
            {
                Application.DoEvents();
                Thread.Sleep(400);
                Dots++;
                if (Dots == 3)
                {
                    Dots = 0;
                }
                switch (Dots)
                {
                case 0:
                    Text = "Finding Key.   |" + RLD.FindProgress;
                    break;

                case 1:
                    Text = "Finding Key..  |" + RLD.FindProgress;
                    break;

                default:
                    Text = "Finding Key... |" + RLD.FindProgress;
                    break;
                }
            }

            if (Key.Length == 0)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();

            fd.Title  = "Select a Script...";
            fd.Filter = "All ExHIBIT Scripts File|*.rld";
            if (fd.ShowDialog() == DialogResult.OK)
            {
                rld = new RLD(System.IO.File.ReadAllBytes(fd.FileName));
                string[] STR = rld.Import();
                Strs.Items.Clear();
                foreach (string Dialog in STR)
                {
                    Strs.Items.Add(Dialog);
                }
            }
        }
Esempio n. 5
0
        private bool DoubleThreadBruteForce(byte[] Script)
        {
            Thread T1 = new Thread(() => {
                uint Key    = 0;
                bool Sucess = RLD.FindKey(Script, out Key, false);
                if (Sucess)
                {
                    this.Key = Key;
                }
                else
                {
                    Key = uint.MaxValue;
                }
            });
            Thread T2 = new Thread(() => {
                uint Key    = 0;
                bool Sucess = RLD.FindKey(Script, out Key, true);
                if (Sucess)
                {
                    this.Key = Key;
                }
                else
                {
                    Key = uint.MaxValue;
                }
            });

            T1.Start();
            T2.Start();
            uint t    = 400;
            uint Dots = 2;

            while (Key == 0)
            {
                Application.DoEvents();
                Thread.Sleep(100);
                t -= 100;
                if (t <= 0)
                {
                    t = 400;
                    Dots++;
                    if (Dots == 3)
                    {
                        Dots = 0;
                    }
                    switch (Dots)
                    {
                    case 0:
                        Text = "Finding Key.";
                        break;

                    case 1:
                        Text = "Finding Key..";
                        break;

                    default:
                        Text = "Finding Key...";
                        break;
                    }
                }
            }
            if (T1.IsAlive)
            {
                T1.Abort();
            }
            if (T2.IsAlive)
            {
                T2.Abort();
            }
            if (Key == uint.MaxValue)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 6
0
        /* C A L C  R E P O R T */

        /*----------------------------------------------------------------------------
        *       %%Function: CalcReport
        *       %%Qualified: bg.Reporter.CalcReport
        *       %%Contact: rlittle
        *
        *  ----------------------------------------------------------------------------*/
        public void Calc()
        {
            m_plrld = new ArrayList();

            // ok, let's walk through and figure out what gets reported and what doesn't
            //
            // first, draw the date we are working with.
            BGE      bge       = (BGE)m_slbge.GetByIndex(0);
            DateTime dttmFirst = new DateTime(bge.Date.Year, bge.Date.Month, bge.Date.Day);

            int ibge, ibgeMax;

            ibge    = 0;
            ibgeMax = m_slbge.Values.Count;
            RLD rld = new RLD();

            while (ibge < ibgeMax)
            {
                float []  dMeals   = { 8.0F, 12.0F, 18.0F };            // our defaults for meals
                float     dHours   = 0.0F;
                string [] rgsDay   = { "S", "M", "T", "W", "T", "F", "S" };
                bool []   rgfMeals = { false, false, false };

                while (ibge < ibgeMax)
                {
                    bge = (BGE)m_slbge.GetByIndex(ibge);
                    if (!bge.InterpReading)
                    {
                        break;
                    }
                    ibge++;
                }

                DateTime dttm        = new DateTime(bge.Date.Year, bge.Date.Month, bge.Date.Day);
                DateTime dttmNextDay = dttm.AddHours(29.5);        // next day is 4:30am the next day
                int      ibgeT       = ibge;
                rld.dttm = dttm;
                rld.sDay = rgsDay[(int)dttm.DayOfWeek];
                if (dttm.DayOfWeek == DayOfWeek.Sunday)
                {
                    rld.sDay        = dttm.ToString("M-dd");
                    rld.sDateHeader = dttm.ToString("d");
                }

                // let's see what meals we have manually accounted for...
                while (bge.Date < dttmNextDay)
                {
                    dHours = bge.Date.Hour + bge.Date.Minute / 60.0F;

                    if (bge.InterpReading)
                    {
                    }
                    else if (bge.Type == BGE.ReadingType.Breakfast)
                    {
                        dMeals[0]   = dHours;
                        rgfMeals[0] = true;
                    }
                    else if (bge.Type == BGE.ReadingType.Lunch)
                    {
                        dMeals[1]   = dHours;
                        rgfMeals[1] = true;
                    }
                    else if (bge.Type == BGE.ReadingType.Dinner)
                    {
                        dMeals[2]   = dHours;
                        rgfMeals[2] = true;
                    }

                    if (ibgeT + 1 >= ibgeMax)
                    {
                        break;
                    }

                    bge = (BGE)m_slbge.GetByIndex(++ibgeT);
                }

                // ok, we have figured out the meal boundaries.  now lets match the readings...
                // any reading within 1 hour of the meal time is considered a "before", and the first reading
                // between 2 hours and 3 hours after meal time is considered "after"
                bge = (BGE)m_slbge.GetByIndex(ibgeT = ibge);
                int   iMealNext      = 0;
                bool  fBeforeMatched = false;
                int   readingBefore  = 0;
                int   readingBed     = 0;
                int   readingFirst   = 0;     // the first reading of the day will serve as the "pre-breakfast" unless we get a better reading.
                float dBedMin        = dMeals[iMealDinner] + 2.0F;
                bool  fMealBumped    = false;

                while (bge.Date < dttmNextDay)
                {
                    while (bge.Date < dttmNextDay)
                    {
                        bge = (BGE)m_slbge.GetByIndex(ibgeT);
                        if (!bge.InterpReading)
                        {
                            break;
                        }
                        if (ibgeT + 1 >= ibgeMax)
                        {
                            break;
                        }
                        ibgeT++;
                    }
                    dHours = bge.Date.Hour + bge.Date.Minute / 60.0F;

                    // don't duplicate comments...
                    if (!fMealBumped && bge.FullComment.Length > 0)
                    {
                        if (rld.sComment.Length > 0)
                        {
                            rld.sComment += "; ";
                        }

                        rld.sComment += bge.FullComment;
                    }

                    fMealBumped = false;
                    if (bge.Date.Day == dttmNextDay.Day)
                    {
                        dHours += 24.0F;
                    }

                    if (readingFirst == 0 && dHours <= dMeals[iMealBreakfast])
                    {
                        readingFirst = bge.Reading;
                    }

                    if (iMealNext <= iMealDinner)
                    {
                        // are we looking for a 'before' reading?

                        if ((iMealNext == iMealBreakfast && bge.Type == BGE.ReadingType.Breakfast) ||
                            (iMealNext == iMealLunch && bge.Type == BGE.ReadingType.Lunch) ||
                            (iMealNext == iMealDinner && bge.Type == BGE.ReadingType.Dinner))
                        {
                            rld.mpimd[iMealNext].nCarbs = bge.Carbs;
                        }

                        if (!fBeforeMatched &&
                            bge.Reading != 0 &&
                            dHours >= dMeals[iMealNext] - m_dHoursBefore && dHours <= dMeals[iMealNext])
                        {
                            // got a "before" match
                            readingBefore = bge.Reading;
                        }

                        // did we find a "before" reading for the current meal and are looking
                        // for that meal (or a reading post-meal) to confirm that this is the last
                        // "before" reading?

                        if (readingBefore != 0 && !fBeforeMatched && dHours > dMeals[iMealNext])
                        {
                            rld.mpimd[iMealNext].nBefore = readingBefore;
                            fBeforeMatched = true;
                        }

                        // does this reading qualify as an 'after' reading?
                        if (dHours >= dMeals[iMealNext] + m_dHoursAfter && dHours <= dMeals[iMealNext] + 4.0)
                        {
                            // got an "after" match
                            rld.mpimd[iMealNext].nAfter = bge.Reading;
                            iMealNext++;
                            fBeforeMatched = false;
                            if (readingBefore != 0)
                            {
                                readingFirst = 0;
                            }
                            readingBefore = 0;
                            fMealBumped   = true;
                        }

                        if (!fMealBumped)
                        {
                            // check to see if we are ready to bump to the next meal
                            if (dHours > dMeals[iMealNext] + 4.0)
                            {
                                iMealNext++;
                                fBeforeMatched = false;
                                if (readingBefore != 0)
                                {
                                    readingFirst = 0;
                                }
                                readingBefore = 0;
                                fMealBumped   = true;
                            }
                        }

                        if (fMealBumped && iMealNext == iMealLunch)
                        {
                            if (readingFirst != 0)
                            {
                                // we still have a "first reading" which means that the breakfast
                                // meal never posted a before reading.  use that first reading now.
                                rld.mpimd[iMealBreakfast].nBefore = readingFirst;
                                readingFirst = 0;
                            }
                        }

                        if (!fMealBumped && ibgeT + 1 >= ibgeMax)
                        {
                            break;
                        }
                    }

                    if (dHours >= dBedMin)
                    {
                        readingBed = bge.Reading;
                    }

                    // if we bumped the meal, then go through again considering this reading
                    // for the next meal.
                    if (!fMealBumped)
                    {
                        if (ibgeT + 1 >= ibgeMax)
                        {
                            break;
                        }
                        bge = (BGE)m_slbge.GetByIndex(++ibgeT);
                    }
                }
                // need to flush everything here
                if (!fBeforeMatched && readingBefore != 0)
                {
                    rld.mpimd[iMealNext].nBefore = readingBefore;
                }
                if (!fBeforeMatched && iMealNext == iMealBreakfast && readingFirst != 0)
                {
                    rld.mpimd[iMealNext].nBefore = readingFirst;
                }

                rld.nBedReading = readingBed;
                m_plrld.Add(rld);
                rld = new RLD();

                // consume the rest of the day
                ibge = ibgeT;
                bge  = (BGE)m_slbge.GetByIndex(ibge);
                while (bge.Date < dttmNextDay)
                {
                    ibge++;
                    if (ibge >= ibgeMax)
                    {
                        break;
                    }

                    bge = (BGE)m_slbge.GetByIndex(ibge);
                }
            }
            // at this point, we have all the data we'll ever want...
        }
Esempio n. 7
0
	/* C A L C  R E P O R T */
	/*----------------------------------------------------------------------------
		%%Function: CalcReport
		%%Qualified: bg.Reporter.CalcReport
		%%Contact: rlittle

	----------------------------------------------------------------------------*/
	public void Calc()
	{
		m_plrld = new ArrayList();

		// ok, let's walk through and figure out what gets reported and what doesn't
		//
		// first, draw the date we are working with.
		BGE bge = (BGE)m_slbge.GetByIndex(0);
		DateTime dttmFirst = new DateTime(bge.Date.Year, bge.Date.Month, bge.Date.Day);

		int ibge, ibgeMax;

		ibge = 0;
		ibgeMax = m_slbge.Values.Count;
		RLD rld = new RLD();

		while (ibge < ibgeMax)
			{
			float []dMeals = { 8.0F, 12.0F, 18.0F };	// our defaults for meals
			float dHours = 0.0F;
			string []rgsDay = { "S", "M", "T", "W", "T", "F", "S" };
			bool []rgfMeals = { false, false, false };

			while (ibge < ibgeMax)
				{
				bge = (BGE)m_slbge.GetByIndex(ibge);
				if (!bge.InterpReading)
					break;
				ibge++;
				}

			DateTime dttm = new DateTime(bge.Date.Year, bge.Date.Month, bge.Date.Day);
			DateTime dttmNextDay = dttm.AddHours(29.5);// next day is 4:30am the next day
			int ibgeT = ibge;
			rld.dttm = dttm;
			rld.sDay = rgsDay[(int)dttm.DayOfWeek];
			if (dttm.DayOfWeek == DayOfWeek.Sunday)
				{
				rld.sDay = dttm.ToString("M-dd");
				rld.sDateHeader = dttm.ToString("d");
				}

			// let's see what meals we have manually accounted for...
			while (bge.Date < dttmNextDay)
				{
				dHours = bge.Date.Hour + bge.Date.Minute / 60.0F;

				if (bge.InterpReading)
					{
					}
				else if (bge.Type == BGE.ReadingType.Breakfast)
					{
					dMeals[0] = dHours;
					rgfMeals[0] = true;
					}
				else if (bge.Type == BGE.ReadingType.Lunch)
					{
					dMeals[1] = dHours;
					rgfMeals[1] = true;
					}
				else if (bge.Type == BGE.ReadingType.Dinner)
					{
					dMeals[2] = dHours;
					rgfMeals[2] = true;
					}

				if (ibgeT + 1 >= ibgeMax)
					break;

				bge = (BGE)m_slbge.GetByIndex(++ibgeT);
				}

			// ok, we have figured out the meal boundaries.  now lets match the readings...
			// any reading within 1 hour of the meal time is considered a "before", and the first reading
			// between 2 hours and 3 hours after meal time is considered "after"
			bge = (BGE)m_slbge.GetByIndex(ibgeT = ibge);
			int iMealNext = 0;
			bool fBeforeMatched = false;
			int readingBefore = 0;
			int readingBed = 0;
			int readingFirst = 0; // the first reading of the day will serve as the "pre-breakfast" unless we get a better reading.
			float dBedMin = dMeals[iMealDinner] + 2.0F;
			bool fMealBumped = false;

			while (bge.Date < dttmNextDay)	
				{
				while (bge.Date < dttmNextDay)
					{
					bge = (BGE)m_slbge.GetByIndex(ibgeT);
					if (!bge.InterpReading)
						break;
					if (ibgeT + 1 >= ibgeMax)
						break;
					ibgeT++;
					}
				dHours = bge.Date.Hour + bge.Date.Minute / 60.0F;

				// don't duplicate comments...
				if (!fMealBumped && bge.FullComment.Length > 0)
					{
					if (rld.sComment.Length > 0)
						rld.sComment += "; ";

					rld.sComment += bge.FullComment;
					}

				fMealBumped = false;
				if (bge.Date.Day == dttmNextDay.Day)
					dHours += 24.0F;

				if (readingFirst == 0 && dHours <= dMeals[iMealBreakfast])
					readingFirst = bge.Reading;

				if (iMealNext <= iMealDinner)
					{
					// are we looking for a 'before' reading?

					if ((iMealNext == iMealBreakfast && bge.Type == BGE.ReadingType.Breakfast)
						|| (iMealNext == iMealLunch && bge.Type == BGE.ReadingType.Lunch)
						|| (iMealNext == iMealDinner && bge.Type == BGE.ReadingType.Dinner))
						{
						rld.mpimd[iMealNext].nCarbs = bge.Carbs;
						}

					if (!fBeforeMatched
						&& bge.Reading != 0
						&& dHours >= dMeals[iMealNext] - m_dHoursBefore && dHours <= dMeals[iMealNext])
						{
						// got a "before" match
						readingBefore = bge.Reading;
						}

					// did we find a "before" reading for the current meal and are looking
					// for that meal (or a reading post-meal) to confirm that this is the last
					// "before" reading?

					if (readingBefore != 0 && !fBeforeMatched && dHours > dMeals[iMealNext])
						{
						rld.mpimd[iMealNext].nBefore = readingBefore;
						fBeforeMatched = true;
						}

					// does this reading qualify as an 'after' reading?
					if (dHours >= dMeals[iMealNext] + m_dHoursAfter && dHours <= dMeals[iMealNext] + 4.0)
						{
						// got an "after" match
						rld.mpimd[iMealNext].nAfter = bge.Reading;
						iMealNext++;
						fBeforeMatched = false;
						if (readingBefore != 0)
							readingFirst = 0;
						readingBefore = 0;
						fMealBumped = true;
						}

					if (!fMealBumped)
						{
						// check to see if we are ready to bump to the next meal
						if (dHours > dMeals[iMealNext] + 4.0)
							{
							iMealNext++;
							fBeforeMatched = false;
							if (readingBefore != 0)
								readingFirst = 0;
							readingBefore = 0;
							fMealBumped = true;
							}
						}

					if (fMealBumped && iMealNext == iMealLunch)
						{
						if (readingFirst != 0)
							{
							// we still have a "first reading" which means that the breakfast
							// meal never posted a before reading.  use that first reading now.
							rld.mpimd[iMealBreakfast].nBefore = readingFirst;
							readingFirst = 0;
							}
						}

					if (!fMealBumped && ibgeT + 1 >= ibgeMax)
						{
						break;
						}

					}

				if (dHours >= dBedMin)
					readingBed = bge.Reading;

				// if we bumped the meal, then go through again considering this reading
				// for the next meal.
				if (!fMealBumped)
					{
					if (ibgeT + 1 >= ibgeMax)
						break;
					bge = (BGE)m_slbge.GetByIndex(++ibgeT);
					}
				}
			// need to flush everything here
			if (!fBeforeMatched && readingBefore != 0)
				{
				rld.mpimd[iMealNext].nBefore = readingBefore;
				}
			if (!fBeforeMatched && iMealNext == iMealBreakfast && readingFirst != 0)
				{
				rld.mpimd[iMealNext].nBefore = readingFirst;
				}

			rld.nBedReading = readingBed;
			m_plrld.Add(rld);
			rld = new RLD();

			// consume the rest of the day
			ibge = ibgeT;
			bge = (BGE)m_slbge.GetByIndex(ibge);
			while (bge.Date < dttmNextDay)
				{
				ibge++;
				if (ibge >= ibgeMax)
					break;

				bge = (BGE)m_slbge.GetByIndex(ibge);
				}
			}
		// at this point, we have all the data we'll ever want...

	}
Esempio n. 8
0
	/* P A I N T  L I N E */
	/*----------------------------------------------------------------------------
		%%Function: PaintLine
		%%Qualified: bg.Reporter.PaintLine
		%%Contact: rlittle

	----------------------------------------------------------------------------*/
	void PaintLine(Graphics gr, RLD rld, int iLine)
	{
		int iMeal;

		DrawTextInColumn(gr, rld.sDay, m_ptb.fontText, m_ptb.brushText, 0, YFromLine(iLine), 1, HorizontalAlignment.Center);

		for (iMeal = 0; iMeal <= iMealDinner; iMeal++)
			{
			if (rld.mpimd[iMeal].nBefore > 0)
				DrawTextInColumn(gr, rld.mpimd[iMeal].nBefore.ToString(), m_ptb.fontText, m_ptb.brushText, 1 + iMeal * 3, YFromLine(iLine), 1, HorizontalAlignment.Right);
			if (rld.mpimd[iMeal].nCarbs > 0)
				DrawTextInColumn(gr, rld.mpimd[iMeal].nCarbs.ToString(), m_ptb.fontText, m_ptb.brushText, 2 + iMeal * 3, YFromLine(iLine), 1, HorizontalAlignment.Center);
			if (rld.mpimd[iMeal].nAfter > 0)
				DrawTextInColumn(gr, rld.mpimd[iMeal].nAfter.ToString(), m_ptb.fontText, m_ptb.brushText, 3 + iMeal * 3, YFromLine(iLine), 1, HorizontalAlignment.Right);
			}

		DrawTextInColumn(gr, rld.nBedReading.ToString(), m_ptb.fontText, m_ptb.brushText, icolBed, YFromLine(iLine), 1, HorizontalAlignment.Right);
		DrawTextInColumn(gr, /*rld.sDateHeader + "] " + */rld.sComment, m_ptb.fontText, m_ptb.brushText, icolComments, YFromLine(iLine), 1, HorizontalAlignment.Left);
	}