Пример #1
0
        //description:method used to check input validation.If the input format is invaild,
        //            there will be an error message prompts and the encryptWord object doesnt
        //            change. If the input is valid, there will be six encryptWord object that set
        //            with the input words.
        //precondition: none
        //postCondition: if information is valid, the encryptWord object would call for set method to
        //               do the encryption based on input words.
        public void CheckInputValid(string[] word)
        {
            for (int K = 0; K < word.Length; K++)
            {
                a[K] = new encryptWord();
                string curWord = word[K];


                if (a[K].setEncryptWord(curWord) == false || curWord.Length < 4)
                {
                    Console.WriteLine(curWord + "  Can not be encrypt due to uncorrect format");
                    Console.WriteLine("Correct format: long than 4 character and lower case alphabet letter\n");
                }
            }
        }
Пример #2
0
        //description: this is the method to test the reset function of one encryptWord object.
        //             The encryptWord object is defined in the below. It would display state and
        //             encryptResult before calling reset. Then it would displaying the same information
        //             after the reset. Thus, it shows how success the encryptWord class 's reset work.
        //precondition: none
        //postCondition: State would change from off to on after the method. EncryptResult will be different
        //               because of different shift number.
        public void testReset()
        {
            b = new encryptWord();
            b.setEncryptWord("verytired");
            String s = String.Format("{0,6} {1,15}{2,18}\n\n", "Original Word", "EncryptResult", "EncryptState");

            s += String.Format(" {0,6} {1,15} {2,18:NO}", b.getOriginal(), b.getResult(), b.checkState());
            Console.WriteLine(s);

            Console.WriteLine("\nAfter correctly guess the number: ");
            b.EncryptWordCheck(b.getRdm());
            Console.WriteLine("\n\nAfter reset:   ");
            b.reset();
            String d = String.Format("{0,6} {1,15}{2,18}\n\n", "Original Word", "EncryptResult", "EncryptState");

            d += String.Format(" {0,6} {1,15} {2,18:NO}", b.getOriginal(), b.getResult(), b.checkState());
            Console.WriteLine(d);
        }