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...
Consider the following page reference string:5, 1, 5, 5, 3, 6, 2, 3, 0 , 7,...
Consider the following page reference string:5, 1, 5, 5, 3, 6, 2, 3, 0 , 7, 2, 5, 2, 1, 7, 2, 3, 1, 4, 6.Assuming demand paging with three frames, how many page faults would occur for the following replacement algorithms?• LRU replacement• FIFO replacement• Optimal replacement
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...
1. Int abc; 2. Int def = 8; 3. abc = def; ➢ Describe the procedure...
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(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 virtual page reference sequence: page 1, 2, 3, 4, 2, 1, 5, 6,...
Consider the following virtual page reference sequence: page 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3. This indicates that these particular pages need to be accessed by the computer in the order shown. Consider each of the following 4 algorithm-frame combinations: LRU with 3 frames FIFO with 3 frames LRU with 4 frames FIFO with 4 frames Print a copy of this page. For each of the 4 combinations, below, move from left to right as...
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
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT