Write a program called Progld which can encode and decode ASCII text files, i.e., any file...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program called "Progld" which can encode and decode ASCII text files, i.e., any file you can view and make sense of such as source code or an html file. Since the goal is not to prevent bad guys from reading your files, we take a simple approach based on systematic character shifting. Computers represent alphanumeric characters using what is called an ASCII code which is nothing more than a a unique 8-bit number. For example, newline ' ' is 10 (0x0A), space" is 32 (0x20), digit '0' is 48 (0x30), letter 'A' is 65 (0x41) while letter 'a' is 97 (0x61) and so forth. (the Unix command "man 7 ascii" will show you all the encodings). Since alphanumeric characters are integer numbers, we can manipulate them. For example, 'a'+1 produces 'b' and 'a'+2 produces 'c'. We will use this idea to change all letters the same way. To keep things interesting, we will make sure lower case letters remain lower case and upper case letters remain upper case. We will not change white space, digits, and other characters. In order to this, you need to determine whether a character represents a letter and if so, whether it is lower or upper case. Use the library functions "isalpha", "islower", and "isupper" to get that job done. More about these below. The tricky bit is to ensure the encoding stays within the realm of lower and upper case letters. For example, 'z'+1 should be mapped to 'a', 'y'+4 should be mapped to 'c', and so forth. When you decode, you likewise need to ensure that 'a'-1 maps to 'z' and 'c'-4 maps to 'y'. This is not hard to do, but you need to be careful when you implement the cyclic mappings. How will the program know whether to encode or decode and how will it know which number to add or subtract to each letter? You tell it using command line arguments. The first is either "-encode" or "-decode". The second is an integer in the range 0-9. UNIX /Progid -encode 4 You can't read this! Csy ger'x vieh xlmw! UNIX> ./Progid -encode 4./Progid -decode 4 You can't read this! You can't read this! Your program must check that the correct number and type of command line arguments is given. If not, an error message should be printed to stderr and program execution stopped. The encoding and decoding should be carried out on a textline-by-textline basis using functions "encode(string&,int)" and "decode(string&,int)". The two arguments are a reference to a textline and the magic shift you will apply to the lower and upper case letters in it. The function "getline(istream&, string&)" can be used to read textlines one at a time. Write a program called "Progld" which can encode and decode ASCII text files, i.e., any file you can view and make sense of such as source code or an html file. Since the goal is not to prevent bad guys from reading your files, we take a simple approach based on systematic character shifting. Computers represent alphanumeric characters using what is called an ASCII code which is nothing more than a a unique 8-bit number. For example, newline ' ' is 10 (0x0A), space" is 32 (0x20), digit '0' is 48 (0x30), letter 'A' is 65 (0x41) while letter 'a' is 97 (0x61) and so forth. (the Unix command "man 7 ascii" will show you all the encodings). Since alphanumeric characters are integer numbers, we can manipulate them. For example, 'a'+1 produces 'b' and 'a'+2 produces 'c'. We will use this idea to change all letters the same way. To keep things interesting, we will make sure lower case letters remain lower case and upper case letters remain upper case. We will not change white space, digits, and other characters. In order to this, you need to determine whether a character represents a letter and if so, whether it is lower or upper case. Use the library functions "isalpha", "islower", and "isupper" to get that job done. More about these below. The tricky bit is to ensure the encoding stays within the realm of lower and upper case letters. For example, 'z'+1 should be mapped to 'a', 'y'+4 should be mapped to 'c', and so forth. When you decode, you likewise need to ensure that 'a'-1 maps to 'z' and 'c'-4 maps to 'y'. This is not hard to do, but you need to be careful when you implement the cyclic mappings. How will the program know whether to encode or decode and how will it know which number to add or subtract to each letter? You tell it using command line arguments. The first is either "-encode" or "-decode". The second is an integer in the range 0-9. UNIX /Progid -encode 4 You can't read this! Csy ger'x vieh xlmw! UNIX> ./Progid -encode 4./Progid -decode 4 You can't read this! You can't read this! Your program must check that the correct number and type of command line arguments is given. If not, an error message should be printed to stderr and program execution stopped. The encoding and decoding should be carried out on a textline-by-textline basis using functions "encode(string&,int)" and "decode(string&,int)". The two arguments are a reference to a textline and the magic shift you will apply to the lower and upper case letters in it. The function "getline(istream&, string&)" can be used to read textlines one at a time.
Expert Answer:
Posted Date:
Students also viewed these programming questions
-
After reading Catch Engineering Partnership v. Mai, 2023 ABKB 279, the court assessed Catch's 2021 damages attributable to Mr. Mai in the amount of (Put your answer in as a dollar figure - ex-...
-
DON'T SUMMARIZE JUST PARAGRAPH OF WHAT YOU THOUGHT/LEARNED CHAPTER 13 - The phrase "garbage in, garbage out" highlights the importance of input controls. If the data entered into a system are...
-
Python and most Python libraries are free to download or use, though many users use Python through a paid service. Paid services help IT organizations manage the risks associated with the use of...
-
Consider the following set of data where an experiment was done to determine the molarity of a solute. What mass of sample is needed to reduce the %RSD to 0.10% if the sampling constant is 17.3 g?...
-
A flower shop uses 250 clay pots a month. The pots are purchased for $2 each. Annua1 holding cost is estimated to be 30 percent of purchase cost, and ordering cost is $20 per order. The manager has...
-
The effect of a number of reheat stages on the ideal steam reheat cycle is to be studied. Repeat Problem 11.37 using two reheat stages, one stage at 1.2 MPa and the second at 0.2 MPa, instead of the...
-
The following processes were identified by the Bessie Bread Company. Each process is treated as a separate profit centre, and transfer prices are charged in internal transfers between internal...
-
The balance in retained earnings on January 1, 2014, for Palmer Inc. was $800,000. During the year, the corporation paid cash dividends of $90,000 and distributed a stock dividend of $8,000. In...
-
2. For the triangle shown below Given b=150mm, a =200mm and B=45?. find the angle C and the side c C B A b 20 a C
-
Required information [The following information applies to the questions displayed below.] The following information is available for Lock-Tite Company, which produces special-order security products...
-
A company has the following information. What is days' inventory outstanding? Average total assets $2,320,600 Average fixed assets 975,000 Total revenue 3,436,000 Cost of goods sold 2,365,000 Average...
-
Calculate the MONTHLY straight line depreciation expense for the following assets: a. Vehicle purchased for $35,000. The vehicle has a salvage value of $2,500 and an estimated useful life of 4 years...
-
Charming Clothiers manufactures neckties and bow ties. The company has the following information: The company s sales price is $ 3 0 per unit. The variable costs of producing bowties is $ 1 8 per...
-
Debit Credit Account Balances Cash = $4,000 Buildings = $15,000 Accounts Payable = $3,000 Common Stock = $9,000 Retained Earnings = $5,000 Service Revenue = $13,000 Salaries Expense = $11,000 What is...
-
Case brief assignment. The case you must locate and summarize is: R. v. Mohan, [1994] 2 S.C.R. 9 Source: https://scc-csc.lexum.com/scc-csc/scc-csc/en/item/1131/index.do Breakdown of Marks and...
-
Question: Pragmatic Data Science utilizing information composition by programming dialects Models Points Section 1 - Question 1 and 2 - Give perceptions to dissemination plots and box plots - boxplot...
-
Why do markets typically lead to an efficient outcome for buyers and sellers?
-
The production budget for cars for May (in units) is a. 6,500 b. 11,000 c. 4,500 d. 10,100 Munch Enterprises makes a small toy car that is voice activated. Projected sales for the next four months...
-
The production budget for cars for May (in units) is a. 6,500 b. 11,000 c. 4,500 d. 10,100
-
The total cost of goods sold for June is a. $103,500 b. $128,800 c. 57,500 d. \($232,300\) Munch Enterprises makes a small toy car that is voice activated. Projected sales for the next four months...
Study smarter with the SolutionInn App