Questions
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a...

introduction: C PROGRAMMING

For this assignment you will write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the text. The first number denotes the position of a word in the key text (starting at 0), and the second number denotes the position of the letter in the word (also starting at 0). For instance, given the following key text (the numbers correspond to the index of the first word in the line)

[0] 'Twas brillig, and the slithy toves Did gyre and gimble in the wabe;

[13] All mimsy were the borogoves, And the mome raths outgrabe.

[23] "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!

[36] Beware the Jubjub bird, and shun The frumious Bandersnatch!"

[45] He took his vorpal sword in hand: Long time the manxome foe he sought—

The word "computer" can be encoded with the following pairs of numbers:

35,0 catch!

5,1 toves

43,3 frumious

48,3 vorpal

22,1 outgrabe.

34,3 that

23,6 "Beware

7,2 gyre

Placing these pairs into a cipher text, we get the following:

35,0,5,1,43,3,48,3,22,1,34,3,23,6,7,2

If you are encoding a phrase, rather than just a single word, spaces in the original english phrase will also appear in the ciphered text. So, the phrase "all done" (using the above Jabberwocky poem) might appear as: 0,3,1,4,13,1 6,0,46,2,44,2,3,2

Only spaces in the key text should be considered delimiters. All other punctuation in the key text are to be considered part of a key word. Thus the first word in the Jabberwocky poem, 'Twas, will have the following characters and positions for key word 0:

Position 0: '

Position 1: T

Position 2: w

Position 3: a

Position 4: s

Developing the Program:

You should approach this assignment in several parts. The first part will be to write a menu driven program that prompts the user for the following actions:

  1. Read in the name of a text file to use as a cipher key
  2. Create a cipher using the input text file (and save the result to a file)
  3. Decode an existing cipher (prompt user for a file to read containing the cipher text)
  4. Exit the program

For each choice, create a stub function that will be completed in the remaining steps.

After testing your menu, continue to fill in the stub functions with the following specifications:

Choice #1

For this menu choice, you will prompt the user for the name of a cipher text file (such as the Declaration of Independence). You will read this text file line by line, and place each word, in order, in an array of char strings. As you copy each word into the array, you will keep a running count of the number of words in the text file and convert the letters of each word to lower case. You may assume that you will use no more than the first 5,000 words in the text, and no more than the first 15 characters in a word. However, there is no guarantee that the text will have 5000 words or less and any word in the text is 15 characters or less.

Choice #2

If no file has been chosen for Choice #1 (i.e. the user goes directly to Choice #2 without first choosing Choice #1), you will first prompt the user to enter a cipher text and read it into memory (presumably by calling the function that would be called by Choice #1). You will prompt the user to enter a secret message (in plain text - such as "Computer Science is the best major at GMU!") that is terminated by pressing the "Enter" key. You can assume that the length of this message will be less than 1500 characters (including the carriage return and NULL terminator). You will then parse this message, character by character, converting them to lower case as you go, and find corresponding characters in the words found in the key text word array. You can do this by going through each word in the word array, and then each character in each word, until you find a match with the current message character. There are more efficient ways to perform this operation, and you are encouraged to implement them instead of the given method. Once a character match is found, you will write the index of the word and the index of the character to a character string that you will later write out to a text file. Spaces are to be placed into the text as found in the message and will be used to delimit the separate words in the secret message. Once the message has been encoded, prompt the user for the name of a file to save the encoded message to, and save it to that file.

Choice #3

You will prompt the user for the name of a file containing an encoded text (i.e. a file containing number pairs). Your program will read the file and decode the the text using the indexes pairs given for each character in the word and the text file chosen for Choice #1. If no file has been chosen for Choice #1 (i.e. the users goes directly to Choice #3 without first choosing Choice #1), you will prompt the user to enter a cipher text and read it into memory (presumably by calling the function that would be called by Choice #1). Spaces found in the file are to be treated as spaces in the decoded text. You can assume that the number of characters in the encoded text file is 5000 or less, including any carriage returns or NULL terminator characters. Once the text is decoded, print the message to standard output.

Choice #4

Exit the program.

Additional Specifications:

  • In order to introduce some "randomness" in the specific character encoding, you will generate a random number i from 0..9 inclusive (use the last four digits of your G Number as the seed), and use the ith instance of that character found in the text. (If fewer than i instances of the character is found in the text, loop back and continue the search from the beginning of the document.)
    • Example: Suppose the letter to encode is a 'c'. Using the sentences just above, we find that there are the following 'c' characters:
      • In order to introduCe some "randomness" in the speCifiC CharaCter enCoding, you will generate a random number i from 0..9 inClusive (use the last four digits of your G Number as the seed), and use the ith instanCe of that CharaCter found in the text.
      • If the random number returns 6, then you will use the 'c' from the word "inclusive." (Start counting from 0). If the random number returns 2, you would the second c found in the word "specific."
  • If a given character in the secret message is not found in any word of the text, replace that character with the '#' character in the encoded text (a single '#' character replaces a word/position pair).
  • Files and filenames will follow the standard CS262 conventions (username, lab section, etc. at top of file, and as part of filename).
  • Each menu choice (except #4) should call a separate function to perform the operation.
  • You can assume that the message to encrypt or decrypt will be less than 1500 characters.
  • Your program will be compiled using a Makefile

Predefined C functions that may be useful for this project:

strtok()

strlen()

tolower()

atoi()

Options for extra credit:

  1. Use dynamic memory for the arrays (up to 5 points additional credit)
  2. Finding the original Beale treasure and sharing it with your professor (up to 1000 points additional credit)

In: Computer Science

Indicate whether each of the following statements is true, false, or uncertain, and explain your answer...

Indicate whether each of the following statements is true, false, or uncertain, and explain your answer in great detail. If a word or phrase is italicized and bolded your answer must include a concise definition of the word or phrase. You must include graphs when necessary.

How does an economy get out of a recessionary gap? (use a graph.)

In: Economics

assignment in C I have a file that contains a lot of lines with words separated...

assignment in C
I have a file that contains a lot of lines with words separated by spaces ( also contains empty lines as well). I need to read this file line by line and put each word into 2d array. NOTE: i need to skip spaces as well as empty lines. also I need to count each word.

In: Computer Science

Choose three strategies from the “25 Ways to Develop a Growth Mindset” article and explain how...

Choose three strategies from the “25 Ways to Develop a Growth Mindset” article and explain how you will use each strategy in your academic, personal, or professional life to help you develop a growth mindset. 1. Replace the word “failing” with the word “learning.” ? 2. Take risks in the company of others ? 3. Acknowledge and embrace imperfections

In: Psychology

Write a program that takes a string input from the user and then outputs the first...

  1. Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown.

Input: Kean

Output:

K

Ke

Kea

Kean

Kea

Ke

K

In: Computer Science

2. Palindromes A palindrome is a word that reads the same forwards and backwards. For example,...


2.


Palindromes


A palindrome is a word that reads the same forwards and backwards. For example,


\aibohphobia" (the irrational fear of palindromes) is a word that reads the same


forwards and backwards. Write a function called


isPalindrome()


that accepts a


string as a parameter and returns True if the string is a palindrome, False otherwise.


Using the function you created, write a program

Python home work

Python

In: Computer Science

Java Ask the user to input a letter grade in either upper or lower case. You...

Java Ask the user to input a letter grade in either upper or lower case. You are to output a message depending on the grade. When the input is A or a, output the word "Excellent!" When the input is B or b, output "Very Good" When the input is C or c, output "Satisfactory" For any other input you must output the word "Fail".

In: Computer Science

Sally is a 3-year-old girl presenting to the PCP’s office. Sally’s mother states she is having...

Sally is a 3-year-old girl presenting to the PCP’s office. Sally’s mother states she is having “temper tantrums.”

Subjective Data

Mother states Sally eats well

Sleeps 11-12 hours/day

Speaks in four- to five-word sentences

Objective Data

Birth weight: 3 kg

Today’s weight: 13 kg

Height: 90 cm

Speaks in three- to four-word sentences with a 300-word vocabulary

Questions:

  1. Is Sally’s vocabulary appropriate for her age?
  2. Are Sally’s height and weight appropriate for her age?
  3. What information can Sally’s nurse give about her temper tantrums?
  4. What is the goal of discipline for a toddler?

In: Nursing

3. Write a Java program that discover all anagrams of all wordslisted in the input file,...

3. Write a Java program that discover all anagrams of all wordslisted in the input file, “dict.txt”. An anagram of a work is a rearrangement of its letters into a new legal word. Your program should do the following:

a. Read in the given “dict.txt” file and sort it in each word’s canonical form. The canonical form of a word contains the same letters as the original word, but in sorted order

b. Instead of putting the “dict.txt” in the code, ask the user to enter the file name

c. Retrieve a word’s canonical form and write a Comparator to compare words by using their canonical forms.


The input file does not contain punctuation. and the file has over 300 pages.

In: Computer Science

Please provide Python code that does the following: 2) A palindrome is any sequence of characters...

Please provide Python code that does the following:

2) A palindrome is any sequence of characters that reads the same backwards as forwards. One-word examples include:

Dad

madam

rotor

Kayak

redder

noon

For the sake of this exercise, the following may also be considered one-word palindromes:

1881

zap4554paz

That is, numeric strings and “nonsense” strings that read the same backwards as forwards should be classified as palindromes.

Write a program that takes as input a string and determines if it’s a one-word palindrome. Here’s a sample output.

Please enter a string: redder

redder is a palindrome.

Please enter a string: zap4554paz

zap4554paz is a palindrome.

Please enter a string: hello

hello is not a palindrome.

In: Computer Science