Robust and Secure Programming Question Paper
Robust and Secure Programming Question Paper
Complete the following test plan for the code shown above.
Invalid data
Boundary
data
(Total 2 marks)
Q7.
The algorithm below, expressed in pseudo-code, allows three users to log in to a
computer program with individual usernames and passwords.
Page 8 of 11
The valid usernames and passwords are listed below.
Username Password
Rachel 49Class
Sam Smile
Tracey b1K3
(a) Shade in one lozenge in each row of the table below to indicate the most
appropriate data type to use for each listed Variable from the algorithm, when the
algorithm is implemented in a programming language.
validlogin
usernum
(3)
(b) It is suggested that line 09 of the algorithm is replaced with the following line:
The function LEN returns the number of items that are stored in the array that is
passed to it as a parameter.
Explain why using the LEN function would make the algorithm more flexible and why
the suggested replacement line would not work as it is.
as array indexing begins at 0,
___________________________________________________________________
must change line to FOR usernum
<= 0 TO LEN(userlist) - 1,
___________________________________________________________________
otherwise index would try to
access an element outside of the
___________________________________________________________________
array. LEN function allows to
iterate over arrays of varying
___________________________________________________________________
length
___________________________________________________________________
___________________________________________________________________
(3)
(c) It is suggested that lines 08 to 14 of the algorithm are replaced with the following
lines:
FOR usernum ← 0 TO 2
IF username = userlist[usernum]
AND password = passlist[usernum] THEN
validlogin ← True
ELSE
validlogin ← False
Page 9 of 11
ENDIF
ENDFOR
Explain why making this replacement would mean that the algorithm no longer
worked.
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(3)
(d) State which of the three passwords listed in the table above is the least secure and
explain why this is the case.
Smile
Which password:____________________________________________________
Q8.
The pseudocode below is written to make sure that the user enters a value within a given
range.
inp ← USERINPUT
WHILE inp ≤ 0 OR inp ≥ 10
OUTPUT "not in range"
inp ← USERINPUT
ENDWHILE
(a) (i) Tick the set of test data that is the most appropriate to check that the code
works as expected.
Tick one
Test data
box
−1, 0, 9, 10
0, 1, 10, 11
−1, 0, 10, 11
Page 10 of 11
0, 1, 9, 10
(1)
(ii) Why is the set of test data that you have chosen in part (i) likely to be enough
to show that the code above works as expected?
only tests boundary data
______________________________________________________________
______________________________________________________________
(1)
(b) Develop an algorithm using pseudocode or a flowchart that asks the user to create
a new password.
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
(5)
(c) State two possible weaknesses of the passwords that this algorithm would accept.
password that could be too short
1. _________________________________________________________________
___________________________________________________________________
Page 11 of 11