Question

In: Computer Science

Reference: Case Study 5 1. def scramble2Encrypt(plainText ): 2    evenChars = "" 3    oddChars...

Reference: Case Study 5

1. def scramble2Encrypt(plainText ):
2    evenChars = ""
3    oddChars = ""
4    charCount = 0
5    for ch in plainText :
6       if charCount % 2== 0:
7            evenChars = evenChars + ch
8        else:
9             oddChars = oddChars + ch
10        charCount = charCount + 1
11     cipherText = oddChars + evenChars
12     return cipherText

22. (10 points) Refer to the code in Case Study 5. Provide a line-by-line description of what is happening on lines 5 through 10. What are those lines of code actually doing? Please don’t merely translate the code to words. I know that in line 7, we are adding ch to evenChars, but what does that mean? =)

Solutions

Expert Solution

Basically here you are converting a plain text to some sort of encrypted way of text i.e For Ex: you are defining your own salt function to convert the plain text so that you form a new text(cypher text) so that no one understand its representation or meaning except you(because you have defined it in your way). This is done for security purposes. Now lets get into the code.

Line by Line explaination:

Line 5: for ch in plainText :

Here plainText is a string. So the above for loop is iterating over the plainText. For every iteration, ch is nothing but pointing out to each character value in plainText.

Ex: plainText="Hello". for ch in plainText: gives me ch="H",ch="e",ch="l",ch="l",ch="o" over the loop.

Line 6: if charCount % 2== 0:

Initially charCount is 0. This basically checks whether charCount value is even or odd number. If charCount%2==0, then charCount is even. Else, charCount is odd.

Ex: charCount=0 -> even

charCount=3 ->odd

charCount=6 -> even

Line 7: evenChars = evenChars + ch

evenChars is declared as empty string initially. So that if you add some string to it using +, that string will concatenate to evenChars (Note: In python, character is also considered as string)

If the line 6 is satisfied i.e if charCount is even, we add that particular character(ch in for loop) to evenChars string. We keep on doing this when charCount is even.

Line 8: else:

This represents if charCount is not even i.e if charCount is odd.

Line 9: oddChars = oddChars + ch

oddChars is declared as empty string initially. So that if you add some string to it using +, that string will concatenate to oddChars (Note: In python, character is also considered as string)

If charCount is odd, then that character(ch in for loop) will be concatenated to oddChars string. We keep on doing this when charCount is odd.

Line 10: charCount = charCount + 1

(Note: I can see in the above code that indendation is not follwed in Line 10. So ensure that this line is in proper format to, for loop. Else, you will get error while executing the code.)

This basically count the number of characters present in the string plainText. For each iteration of for loop, this charCount will get incremented by 1. So by end of the loop you will get the length of the string plainText.

Ex: plainText="Hello". by end of the for loop, charCount will be 5

#Please dont forget to upvote if you find the solution helpful. Thank you.


Related Solutions

The following page-reference string: 1, 2, 4, 3, 2, 5, 4, 2, 4, 2, 1, 3,...
The following page-reference string: 1, 2, 4, 3, 2, 5, 4, 2, 4, 2, 1, 3, 2, 3, 1, 3, 6, 1, 6, 4. Main memory with 3 frames of 1 kilobyte available and they are all initially empty. Complete a figure, similar to Figure 8.14(in the slides or textbook), showing the frame allocation for each of the following page replacement policies: a. Optimal b. Least recently used c. First-in-first-out Then, find the relative performance of each policy with respect...
please nswer Case Study Exercises 1, 2, and 5 CASE STUDY INFLATION CONSIDERATIONS FOR STOCK AND...
please nswer Case Study Exercises 1, 2, and 5 CASE STUDY INFLATION CONSIDERATIONS FOR STOCK AND BOND INVESTMENTS Background The savings and investments that an individual maintains should have some balance between equity (corporate stocks that rely on market growth and dividend income) and fixed-income investments (bonds that pay dividends to the purchaser and a guaranteed amount upon maturity). When inflation is moderately high, bonds offer a low return relative to stocks because the potential for market growth is not...
Qno.1 Part(A). IN jAVA if 1.Int abc; 2. Int def = 8; 3. abc = def;...
Qno.1 Part(A). IN jAVA if 1.Int abc; 2. Int def = 8; 3. abc = def; ➢ Describe the procedure how much memory will be allocated when these three lines of codes will execute. ➢ Describe what will happened after execution of each of these line of code in term of memory allocation and data storage Qno.1 Part(B) A capacitor is constructed from two conductive metal plates 30cm x 50cm which are spaced 6mm apart from each other, and uses...
Consider the following page reference string: 0, 1, 2, 3, 1, 0, 4, 5, 1, 0,...
Consider the following page reference string: 0, 1, 2, 3, 1, 0, 4, 5, 1, 0, 1, 2, 6, 5, 2, 1, 0, 1, 2, 5 How many page faults would occur for the following replacement algorithms, assuming one, three, five, and seven frames? Remember that all frames are initially empty, so your first unique pages will cost one fault each. Optimal replacement LRU replacement CLOCK replacement FIFO replacement
Case 2 Geo Tech Cash Flow Template (Base Case) Year 0 1 2 3 4 5...
Case 2 Geo Tech Cash Flow Template (Base Case) Year 0 1 2 3 4 5 $600,000.00 $1,080,000.00 $1,050,000.00 $750,000.00 $570,000.00 Revenues Cash Costs Set up $280,000.00 $420,000.00 $280,000.00 $140,000.00 $140,000.00 Other operating $240,000.00 $240,000.00 $360,000.00 $360,000.00 $240,000.00 Depreciation $280,000.00 $280,000.00 $280,000.00 EBIT -$200,000.00 $140,000.00 $130,000.00 $250,000.00 $190,000.00 Taxes -$70,000.00 $49,000.00 $45,500.00 $87,500.00 $66,500.00 Net Operating Income After Taxes -$130,000.00 $91,000.00 $84,500.00 $162,500.00 $123,500.00 Add Depreciation $280,000.00 $280,000.00 $280,000.00 Net Operating Cash Flows $150,000.00 $371,000.00 $364,500.00 $162,500.00 $123,500.00 Recovery of...
500 WORDS PLEASE Explain what are: (1) Reference prices (2) Internal Reference Prices (3) External Reference...
500 WORDS PLEASE Explain what are: (1) Reference prices (2) Internal Reference Prices (3) External Reference Prices –Please give examples of internal and external reference prices.
Direction ratio of line joining (2, 3, 4) and (−1, −2, 1), are: A. (−3, −5, −3) B. (−3, 1, −3) C. (−1, −5, −3) D. (−3, −5, 5)
Direction ratio of line joining (2, 3, 4) and (−1, −2, 1), are:A. (−3, −5, −3)B. (−3, 1, −3)C. (−1, −5, −3)D. (−3, −5, 5)
Assignment 2-Case Study-Chapters: 7, 8, 9 & 12 : - [5 Marks] Case Study When taxes...
Assignment 2-Case Study-Chapters: 7, 8, 9 & 12 : - [5 Marks] Case Study When taxes induce people to change their behavior—such as inducing Jane to buy less pizza—the taxes cause deadweight losses and make the allocation of resources less efficient. As we have already seen, much government revenue comes from the individual income tax in many countries. In a case study in Chapter 8, we discussed how this tax discourages people from working as hard as they otherwise might....
Case study 3. Activity and exercise case study: Mrs. Gomez Mrs. Gomez underwent surgery 2 days...
Case study 3. Activity and exercise case study: Mrs. Gomez Mrs. Gomez underwent surgery 2 days ago for repair of a fractured hip she suffered in a fall. She has an incision over her left hip area that is free of redness with well-approximated edges. She experiences pain upon movement even though she is being adequately medicated for pain. The Physician has ordered daily physical therapy and that Mrs. Gomez be ambulated three times daily. Mrs. Gomez does not want...
QUESTION 6 – CASE STUDY II [5+5+5+5+5 = 25 Marks] Reusable Passwords Case study adapted from:...
QUESTION 6 – CASE STUDY II [5+5+5+5+5 = 25 Marks] Reusable Passwords Case study adapted from: [Brooks hear. ICT Services Management (Custom Edition EBook), Pearson Education Australia, 2015. ProQuest Ebook Central, http://ebookcentral.proquest.com] Reusable Passwords The most common authentication credential is the reusable password, which is a string of characters that a user types to gain access to the resources associated with a certain username (account) on a computer. These are called reusable passwords because the user types the password each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT