Пример #1
0
 public DriverProgram()
 {
     test_WordUnderLengthRequirement           = new EncryptWord("Hi");
     test_WordWithBothUpperAndLowerCaseLetters = new EncryptWord("TeStWoRd");
     test_WordWithASymbolInIt = new EncryptWord("HI!!");
     test_LongerWord          = new EncryptWord("Indubitably");
 }
Пример #2
0
        /*  Description: -- takes in user defined string to use for encryption.
         */
        public string word(string x)
        {
            EncryptWord e = new EncryptWord();

            e.Initiate();
            return(e.encrypt(x));
        }
Пример #3
0
        public static void Main()
        {
            var rnd           = new Random(5);
            int caesar_cipher = rnd.Next(5);

            EncryptWord1.driver.testValidEncryption();
            EncryptWord1.driver.testInvalidInputEncryption();
            string input;

            Console.Write("\n******************READY TO PLAY THE WORD GUESSING GAME ??*****************");
            Console.Write("\n");
label:
            Console.Write("Enter word to be encrypted");
            Console.Write("\n");
            input = Console.ReadLine();
            try
            {
                EncryptWord encryptWord = new EncryptWord(input, caesar_cipher);
                EncryptWord1.driver.userInputOption(ref encryptWord);
            }
            catch (Exception e)
            {
                Console.Write("Received exception :: ");
                Console.Write(e.Source);
                Console.Write("\n");
                goto label;
            }
        }
Пример #4
0
        /*  Description: -- takes in user defined int guess of the shift
         * applied by the cipher.
         */
        public bool guess(int y)
        {
            bool        guessTruth = false;
            EncryptWord e          = new EncryptWord();

            e.Initiate();
            guessTruth = e.makeGuess(y);
            return(guessTruth);
        }
Пример #5
0
        //Description:
        //holds the guessing game. It encrypts the word and takes in the
        //user's guess until they've guessed correctly. It also displays the statistics.
        //Input:
        //first input is the user's choice of word to be encrypted. This word
        //needs to be at least 4 words in length and must not be any numbers or special
        //characters. It's limited to a legal input of lower and upper case characters.
        //multiple words are allowed but the space between them will not be recognized
        //so it will encrypt as one long word.The second input from the user is an int
        //holding the guess shift of the user. We assume the user will not enter any
        //doubles or float or letters in field as they will not be processed.
        //processing:
        //When the game is being played the word can only be encrypted is
        //when entering EncryptWord class the boolean variable controlling on/off is
        //turned off. If encryption is turned on then one will not be able to encrypt
        //a word. The user's word is processed and validated to be 4 characters long.
        //Legal inputs are lower or upper case characters within the alphabet. Once word
        //is encrypted, the boolean controlling on/off is changed to on and the user
        //will continue to guess as long as it stay on. The user will enter only legal
        //inputs - integers. All other inputs are illegal and will not provide a correct
        //shift. Once correct shift is found the statistics are printed out and the
        //EncryptWord class is reset to allow the user to play again. The reset sets
        //the on/off variable to off to allow a new encryption. The statistics will only
        //be displayed if during each guess the encryption is on - if not, it will not
        //process any of the counts. The method also saves the encryptedWord to be able
        //to use in other methods.
        //output:
        //The output of method is the encrypted word and "guess is too low" or "guess is
        //too high" if the user has not entered correct shift. If user enters -1 the
        //output is the end of game as it acts as a reset within the game. If shift is
        //guessed correctly it will display the statistics. AverageGuess is only
        //displayed if more than 1 guess has been entered since correct guess is not
        //considered a "guess".

        static void playGame(string word, EncryptWord encryptWord)
        {
            encryptedWord = encryptWord.Encrypt(word); //variable collects console input
            Console.WriteLine("\nThe encrypted word is: ");
            Console.WriteLine(encryptedWord);
            correctShift = encryptWord.GetShiftCode();
            guess(correctShift, encryptWord); //method will compare user's guess to the
                                              //correct shift
        }
Пример #6
0
        static void Main(string[] args)
        {
            string      userWord;
            EncryptWord e = new EncryptWord();

            e.Initiate();
            userWord = Console.ReadLine();
            Console.WriteLine(e.encrypt(userWord));
            Console.ReadKey();
        }
Пример #7
0
        static int correctShift;       //holds the correct shift throughout the program

        public Driver()
        {
            string word;

            welcome();
            do
            {
                EncryptWord encryptWord = new EncryptWord();//EncryptWord class object
                word = askUserInput(encryptWord);
                playGame(word, encryptWord);
            } while (keepAsking);
            goodBye();
        }
Пример #8
0
        //Description:
        //displays the statistics for current round of guessing game.
        //input:T
        //he function calls upon the EncryptWord class and prints out the count
        //of the statistical values. There's no input as it calls upon the following
        //EncryptWord class getter variables: queries, lowGuess, highGuess,
        //averageGuess.
        //processing:
        //the function only prints out the getters from the EncryptWord
        //class userQueries method. It's this method that processes the count and the
        //printStats function in the driver class displays the output. The avearageGuess
        //is only processed if more than one guess has been provided. If the only guess
        //by the user is the correct one then the averageGuess will not display because
        //the correct answer is not counted in averageGuess.
        //output:
        //prints the count of EncryptWord class queries, lowGuess, highGuess,
        //and averageGuess variables.
        static void printStats(EncryptWord A)
        {
            Console.WriteLine("\nYou had this many guesses: ");
            Console.WriteLine(A.GetQueries());

            if (A.getAverageGuess() > 0)
            {
                Console.WriteLine("Your average guess factor is: ");
                Console.WriteLine(A.getAverageGuess());
            }
            Console.WriteLine("You had this many high guesses: ");
            Console.WriteLine(A.GetHighGuess());
            Console.WriteLine("You had this many low guesses: ");
            Console.WriteLine(A.GetLowGuess());
        }
Пример #9
0
        //description:
        //Method asks user to enter a word they will like to encrypt.
        //input:
        //The input can be character in the ASCII table. However, to be able to
        //encrypt and decrypt properly we assume that the user will only enter lower or
        //upper case alphabetical char. The user can have as many words separated by
        //a space, however, when it's passed to the encryptWord class the space will be
        //eliminated and it will be evaluated as one big word.
        //processing:
        //All characters entered by the user will be validated for length
        //and if it does not meet the minimum length the user will need to continue
        //entering words till it's at least 4 characters. All words separated by a space
        //will be evaluated as one big word - spaces eliminated
        //output:
        //The output will return the user's word as they wrote it. If the user
        //does not enter a word that meets 4 characters or more he/she must continue
        //to enter inputs until a word that meets the requirement is entered.

        static string askUserInput(EncryptWord A)
        {
            string word; //holds user's word
            string united;

            Console.WriteLine("Enter a word(lower or upper case or type quit to end): ");
            united = Console.ReadLine();
            word   = united.Replace(" ", " ");
            if (word.Equals("quit"))
            {
                System.Environment.Exit(0);
            }
            else
            {
                word = validateLengthOfWord(word); //validates word
            }
            return(word);                          //returns non encrypted word
        }
Пример #10
0
        /**
         * Test all the  invalid valid functionality of EncryptWord.
         *  multi pass encryption
         */
        public static void testInvalidInputEncryption()
        {
            Console.Write("\n***************Invalid Inputs*******************");
            Console.Write("\n");
            var rnd           = new Random(5);
            int caesar_cipher = rnd.Next(5);

            try
            {
                EncryptWord encryptWord = new EncryptWord("h3l* ", caesar_cipher);
                encryptWord.encrypt();
            }
            catch (Exception e)
            {
                Console.Write("Received exception for input h31* ");
                Console.Write(e.Source);
                Console.Write("\n");
            }
            try
            {
                EncryptWord encryptWord = new EncryptWord("12345", caesar_cipher);
                encryptWord.encrypt();
            }
            catch (Exception e)
            {
                Console.Write("Received exception for input 12345 ");
                Console.Write(e.Source);
                Console.Write("\n");
            }
            try
            {
                EncryptWord encryptWord = new EncryptWord("a", caesar_cipher);
                encryptWord.encrypt();
            }
            catch (Exception e)
            {
                Console.Write("Received exception for input a ");
                Console.Write(e.Source);
                Console.Write("\n");
            }
        }
Пример #11
0
        //Description:
        //Asks the user to guess the correct shift that encrypted the word. If correct
        //it will provide the user with statistics of the game.
        //Input: legal inputs are only considered integers - no words, special characters,
        //doubles, floats, etc. will be allowed. The user can input any integer they
        //choose, however, the range of the random generator is limited to 26. Even
        //though all integers are okay - the range will be positive so we assume the
        //user will only enter positive numbers except for -1 which will be used to
        //reset game.
        //processing: if a legal input is entered it will compare it to the correct
        //shift code. If there is a match it will exit the do-while loop and display the
        //statistics of the game. If -1 is entered it will exit encryption (reset) and
        //asks the user what they will like to do. If they decide to play again they
        //may choose to do so as everything will be reset.
        //output: with the input being the user's choice of integer the output will be
        //"too low" or "too high" depending on what they have answered. These will
        //continue to display until the correct shift has been entered.  if -1 is the
        //user's input then the output states game has been reset and asks the user what
        //they want to do next. Only if one has guessed correctly will the statistics
        //display on the screen.
        static void guess(int correctShift, EncryptWord encryptWord)
        {
            string userInput;
            int    shift; //holds user's guess - The guess can only be integers

            do
            {
                Console.WriteLine("\nGuess shift between 1 thru 26(Enter -1 to exit current encryption): ");
                userInput = Console.ReadLine();
                shift     = Convert.ToInt32(userInput);
                //shift = Console.Read(); //user cannot input doubles/float/words/negative numbers
                //other than -1
                Console.WriteLine(shift);
                if (shift > correctShift)
                {
                    Console.WriteLine("\nguess is too high");
                }
                else if (shift < correctShift && shift != -1)
                {
                    Console.WriteLine("\nguess is too low");
                }
                encryptWord.SetUserGuess(shift); //every guess is brought to a method
                                                 //that increases count based on guess
            } while (shift != correctShift && shift != -1);
            if (shift == -1)
            {
                encryptWord.Reset(); // encryption is turned off
                System.Environment.Exit(0);
            }
            else
            {
                Console.WriteLine("You've guessed correct!");
                printStats(encryptWord);
                encryptWord.Reset();
            }
        }
Пример #12
0
        public static void testValidEncryption()
        {
            /**testing valid words with lenght more that 4**/
            int guessWord;

            Console.Write("\n******************Testing Senarios*******************");
            Console.Write("\n");
            var rnd = new Random(5);

            guessWord = rnd.Next();
            EncryptWord encryptValidWord1 = new EncryptWord("abcd", guessWord);

            encryptValidWord1.encrypt();
            /**guess valid word**/

            Console.Write("Attempting cipher shift guess with value ");
            Console.Write(rnd.Next(1) % ALPHABET_COUNT);
            Console.Write("\n");
            encryptValidWord1.guessShiftValue(rnd.Next(1));


            Console.Write("Attempting cipher shift guess with value ");
            Console.Write(rnd.Next(2) % ALPHABET_COUNT);
            Console.Write("\n");
            encryptValidWord1.guessShiftValue(rnd.Next(rnd.Next(2) % ALPHABET_COUNT));


            Console.Write("Attempting cipher shift guess with value ");
            Console.Write(rnd.Next(3) % ALPHABET_COUNT);
            Console.Write("\n");
            encryptValidWord1.guessShiftValue(rnd.Next(3));

            Console.Write("Attempting cipher shift guess with value ");
            Console.Write(guessWord % ALPHABET_COUNT);
            Console.Write("\n");
            encryptValidWord1.guessShiftValue(guessWord % ALPHABET_COUNT);


            encryptValidWord1.stats();

            EncryptWord encryptValidWord2 = new EncryptWord("yzaze", rnd.Next(4));

            encryptValidWord2.encrypt();

            /**large word test**/
            EncryptWord encryptLargeWord = new EncryptWord("thisisavalidwordwithverylongnumberofcharactersanditwillwork", rnd.Next(5));

            encryptLargeWord.encrypt();

            /**testing encryption off***/
            EncryptWord encryptWordOFF = new EncryptWord("testingoff", rnd.Next(0));

            encryptWordOFF.encryptOFF();
            encryptWordOFF.encrypt();

            /**testing encryption on***/
            EncryptWord encryptWordON = new EncryptWord("testingon", rnd.Next(0));

            encryptWordON.encryptON();
            encryptWordON.encrypt();
        }
Пример #13
0
        //user inputs
        public static void userInputOption(ref EncryptWord encryptword)
        {
            int    inputOption;
            string input;
            var    rnd = new Random(5);

            while (true)
            {
                Console.Write("Select an option");
                Console.Write("\n");
                Console.Write("0 --> EXITs the application ");
                Console.Write("\n");
                Console.Write("1 --> ENCRYPT the word  ");
                Console.Write("\n");
                Console.Write("2 --> Turns OFF the encryption  ");
                Console.Write("\n");
                Console.Write("3 --> Turns ON the encryption  ");
                Console.Write("\n");
                Console.Write("4 --> RESET the word to initially given word. ");
                Console.Write("\n");
                Console.Write("5 --> Shows the Statistics of guesses performed.");
                Console.Write("\n");
                Console.Write("6 --> Guess the shift value");
                Console.Write("\n");
                Console.Write("7 --> Enter a new value");
                Console.Write("\n");

                //checking the user inputs and responds according to the selection
                inputOption = int.Parse(Console.ReadLine());
                switch (inputOption)
                {
                case 0:
                    Environment.Exit(0);
                    break;

                case 1:
                    encryptword.encrypt();
                    break;

                case 2:
                    encryptword.encryptOFF();
                    break;

                case 3:
                    encryptword.encryptON();
                    break;

                case 4:
                    encryptword.encryptRESET();
                    break;

                case 5:
                    encryptword.stats();
                    break;

                case 6:
                    Console.Write("Guess a value");
                    Console.Write("\n");
                    int guess;
                    guess = int.Parse(Console.ReadLine());
                    encryptword.guessShiftValue(guess);
                    break;

                case 7:
                    Console.Write("Enter a new word");
                    Console.Write("\n");
                    input       = Console.ReadLine();
                    encryptword = new EncryptWord(input, rnd.Next());
                    break;

                default:
                    Console.Write("Enter proper option");
                    Console.Write("\n");
                    break;
                }
            }
        }
Пример #14
0
 //Encapsulates EncryptWord object
 //Pre: None
 //Post: None
 public Driver(String userWord)
 {
     ew            = new EncryptWord(userWord);
     this.userWord = userWord;
 }