Deck 3: Codes and Other Secrets: String Operators and Methods, the Len Built-In Function, Keyword Parameters, User Input

Full screen (f)
exit full mode
Question
What is the string concatenation operator in Python?

A) :
B) +
C) ~
D) *
Use Space or
up arrow
down arrow
to flip the card.
Question
What is the repetition operator in Python?

A) :
B) +
C) ~
D) *
Question
What is the value of 'John'[0]?

A) J
B) 'J'
C) 0
D) Undefined
Question
What function returns the number of characters in a string?

A) range
B) length
C) leng
D) stringlen
Question
Case Study 1:
1. >>> name = "Roy G Biv"
2. >>> first = name[0]
3. >>> first
4. >>> middleChar = name[4]
5. >>> middleChar
6. >>> name[-1]
-Refer to the session in the accompanying Case Study 1. What is printed after line 3?

A) 'R'
B) R
C) 'v'
D) G
Question
Case Study 1:
1. >>> name = "Roy G Biv"
2. >>> first = name[0]
3. >>> first
4. >>> middleChar = name[4]
5. >>> middleChar
6. >>> name[-1]
-Refer to the session in the accompanying case study 1. What is printed after line 6?

A) 'R'
B) R
C) 'v'
D) G
Question
What is the [:] operator called?

A) Cut
B) Index
C) Slice
D) Substring
Question
What is the result of the following code?
'bc' in 'abc'

A) True
B) False
C) 'a'
D) 1
Question
What method can be used to surround a string with spaces in order to make it a certain length?

A) replace
B) count
C) upper
D) center
Question
What function converts a character to its Unicode equivalent?

A) str
B) chr
C) ord
D) num
Question
Case Study 2:
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
-Refer to the code in the accompanying case study 2. What is the name of the % operator used on line 6?

A) Division
B) Modulo
C) Cipher
D) Rail fence
Question
Case Study 2:
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
-Refer to the code in the accompanying case study 2. What type of cipher has been implemented?

A) Transposition
B) Accumulator
C) Substitution
D) Vignère
Question
Python uses the ____ function to ask the user for a single string.

A) string
B) get
C) input
D) prompt
Question
When implementing a substitution cipher in Python, use the ____ method to return the position of any letter in the alphabet.

A) range
B) len
C) position
D) index
Question
When implementing the Vigenère cipher, which step comes first?

A) Use the accumulator pattern to add the ciphertext letter to the ciphertext message.
B) Determine which letter of the key we should use.
C) Return the string as the ciphertext message.
D) Look up the ciphertext letter in the Vigenère square, using the key letter row and plaintext character column.
Question
The concatenation operator joins two strings and adds a space between them.
Question
Although the function call len('abc') returns 3, we would use 'abc'[2] to access the character 'c'.
Question
The find method finds the number of occurrences of one string within another.
Question
The letter 'a' corresponds to the number 0 in the Unicode system.
Question
The process of turning ciphertext into plaintext is called decryption.
Question
Match each line of code with a result below. Assume aString is initialized as below:
aString = "golden gopher football"
-aString.count('o')

A) 4
B) 18
C) 0
D) 1
Question
Match each line of code with a result below. Assume aString is initialized as below:
aString = "golden gopher football"
-aString.find('b')

A) 5
B) 19
C) 1
D) 2
Question
Match each line of code with a result below. Assume aString is initialized as below:
aString = "golden gopher football"
-aString.index('g')

A) 6
B) 20
C) 2
D) 3
Question
Match each line of code with a result below. Assume aString is initialized as below:
aString = "golden gopher football"
-aString.count('oo')

A) 7
B) 21
C) 3
D) 4
Question
What does the term "string" refer to in computer science language, and how is a string defined in Python?
Question
What is the operator represented by the * in the following code? Explain its use.
>>> 'go'*3
Question
Describe the functionality of the string index operator with an example.
Question
One of the easiest ways to encrypt a message is to simply scramble the letters. For example, the word "mango" could be randomly transformed to "nogma." In fact, there are 120 different possible arrangements of the word "mango." Explain why this is not an effective encryption method.
Question
Case Study 2:
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
-Refer to the code in the accompanying Case Study 2. Provide a line-by-line description of what is happening on lines 5 through 10.
Question
Case Study 2:
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
-Refer to the code in the accompanying Case Study 2. Explain how you would reverse the process of scramble2Encrypt in order to decrypt the message.
Question
What is the advantage of a substitution cipher over a transposition cipher?
Question
How effective is a brute force approach to cracking a substitution cipher? Explain your answer.
Question
Provide a high-level summary of the actions needed to encrypt a message using a Vigenère square.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/33
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 3: Codes and Other Secrets: String Operators and Methods, the Len Built-In Function, Keyword Parameters, User Input
1
What is the string concatenation operator in Python?

A) :
B) +
C) ~
D) *
B
2
What is the repetition operator in Python?

A) :
B) +
C) ~
D) *
D
3
What is the value of 'John'[0]?

A) J
B) 'J'
C) 0
D) Undefined
B
4
What function returns the number of characters in a string?

A) range
B) length
C) leng
D) stringlen
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
5
Case Study 1:
1. >>> name = "Roy G Biv"
2. >>> first = name[0]
3. >>> first
4. >>> middleChar = name[4]
5. >>> middleChar
6. >>> name[-1]
-Refer to the session in the accompanying Case Study 1. What is printed after line 3?

A) 'R'
B) R
C) 'v'
D) G
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
6
Case Study 1:
1. >>> name = "Roy G Biv"
2. >>> first = name[0]
3. >>> first
4. >>> middleChar = name[4]
5. >>> middleChar
6. >>> name[-1]
-Refer to the session in the accompanying case study 1. What is printed after line 6?

A) 'R'
B) R
C) 'v'
D) G
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
7
What is the [:] operator called?

A) Cut
B) Index
C) Slice
D) Substring
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
8
What is the result of the following code?
'bc' in 'abc'

A) True
B) False
C) 'a'
D) 1
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
9
What method can be used to surround a string with spaces in order to make it a certain length?

A) replace
B) count
C) upper
D) center
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
10
What function converts a character to its Unicode equivalent?

A) str
B) chr
C) ord
D) num
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
11
Case Study 2:
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
-Refer to the code in the accompanying case study 2. What is the name of the % operator used on line 6?

A) Division
B) Modulo
C) Cipher
D) Rail fence
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
12
Case Study 2:
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
-Refer to the code in the accompanying case study 2. What type of cipher has been implemented?

A) Transposition
B) Accumulator
C) Substitution
D) Vignère
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
13
Python uses the ____ function to ask the user for a single string.

A) string
B) get
C) input
D) prompt
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
14
When implementing a substitution cipher in Python, use the ____ method to return the position of any letter in the alphabet.

A) range
B) len
C) position
D) index
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
15
When implementing the Vigenère cipher, which step comes first?

A) Use the accumulator pattern to add the ciphertext letter to the ciphertext message.
B) Determine which letter of the key we should use.
C) Return the string as the ciphertext message.
D) Look up the ciphertext letter in the Vigenère square, using the key letter row and plaintext character column.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
16
The concatenation operator joins two strings and adds a space between them.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
17
Although the function call len('abc') returns 3, we would use 'abc'[2] to access the character 'c'.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
18
The find method finds the number of occurrences of one string within another.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
19
The letter 'a' corresponds to the number 0 in the Unicode system.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
20
The process of turning ciphertext into plaintext is called decryption.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
21
Match each line of code with a result below. Assume aString is initialized as below:
aString = "golden gopher football"
-aString.count('o')

A) 4
B) 18
C) 0
D) 1
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
22
Match each line of code with a result below. Assume aString is initialized as below:
aString = "golden gopher football"
-aString.find('b')

A) 5
B) 19
C) 1
D) 2
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
23
Match each line of code with a result below. Assume aString is initialized as below:
aString = "golden gopher football"
-aString.index('g')

A) 6
B) 20
C) 2
D) 3
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
24
Match each line of code with a result below. Assume aString is initialized as below:
aString = "golden gopher football"
-aString.count('oo')

A) 7
B) 21
C) 3
D) 4
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
25
What does the term "string" refer to in computer science language, and how is a string defined in Python?
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
26
What is the operator represented by the * in the following code? Explain its use.
>>> 'go'*3
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
27
Describe the functionality of the string index operator with an example.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
28
One of the easiest ways to encrypt a message is to simply scramble the letters. For example, the word "mango" could be randomly transformed to "nogma." In fact, there are 120 different possible arrangements of the word "mango." Explain why this is not an effective encryption method.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
29
Case Study 2:
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
-Refer to the code in the accompanying Case Study 2. Provide a line-by-line description of what is happening on lines 5 through 10.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
30
Case Study 2:
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
-Refer to the code in the accompanying Case Study 2. Explain how you would reverse the process of scramble2Encrypt in order to decrypt the message.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
31
What is the advantage of a substitution cipher over a transposition cipher?
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
32
How effective is a brute force approach to cracking a substitution cipher? Explain your answer.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
33
Provide a high-level summary of the actions needed to encrypt a message using a Vigenère square.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 33 flashcards in this deck.