A program allows a user to save passwords used to login to websites. A stored password is inserted automatically when the user logs into the corresponding website. A student is developing a program to generate a password. The password will be of a fixed format, consisting of three groups of four alphanumeric characters. The groups are separated by the hyphen character '-'. An example of a password is: "FxAf-3haV-Tq49" A global 2D array Secret of type STRING stores the passwords together with the website domain name where they are used. Secret contains 1000 elements organised as 500 rows by 2 columns. Unused elements contain the empty string (""). These may occur anywhere in the array. An example of a part of the array is: Array element | Value ---|--- Secret [27, 1] | "www.thiswebsite.com" Secret [27, 2] | "............." Secret [28, 1] | "www.thatwebsite.com" Secret [28, 2] | "............." Note: • For security, passwords are stored in an encrypted form, shown as "............." in the example. • The passwords cannot be used without being decrypted. • Assume that the encrypted form of a password will not be an empty string. The programmer has started to define program modules as follows: Module | Description ---|--- RandomChar() | • Generates a single random character from within one of the following ranges: | ◦ 'a' to 'z' | ◦ 'A' to 'Z' | ◦ '0' to '9' | • Returns the character Encrypt() | • Takes a password as a parameter of type string | • Returns the encrypted form of the password as a string Decrypt() | • Takes an encrypted password as a parameter of type string | • Returns the decrypted form of the password as a string For reference, relevant ASCII values are as follows: Character range | ASCII range ---|--- 'a' to 'z' | 97 to 122 'A' to 'Z' | 65 to 90 '0' to '9' | 48 to 57
- (a)Write pseudocode for module RandomChar(). You may wish to refer to the insert for a description of the CHR() function. Other functions may also be required.[6]
- (b)A new module is defined as follows: Module | Description ---|--- FindPassword() | • Takes a website domain name as a parameter of type string | • Searches for the website domain name in the array Secret | • If the website domain name is found, the decrypted password is returned | • If the website domain name is not found, a warning message is output, and an empty string is returned Write pseudocode for module FindPassword(). Assume that modules Encrypt() and Decrypt() have already been written.[7]
- (c)The modules Encrypt() and Decrypt() are called from several places in the main program. Identify a method that could have been used to test the main program before these modules were completed. Describe how this would work. Method Description[3]
- (d)A validation function is written to check that the passwords generated are valid. To be valid, each password must: • be 14 characters long • be organised as three groups of four case-sensitive alphanumeric characters. The groups are separated by hyphen characters • not include any duplicated characters, except for the hyphen characters. Note: lower-case and upper-case characters are not the same. For example, 'a' is not the same as 'A'. Give two password strings that could be used to test different areas of the validation rules. Password 1 Password 2[2]
- (e)The RandomChar() module is to be modified so that alphabetic characters are generated twice as often as numeric characters. Describe how this might be achieved.[3]
Mark scheme
Marking points from the official mark scheme (May/June 2022). The mark or mark type is shown in brackets.
- [6] (a) FUNCTION RandomChar() RETURNS CHAR
- [6] (a) DECLARE ThisRange : INTEGER
- [6] (a) DECLARE ThisChar : CHAR
- [6] (a) //First select the range
- [6] (a) ThisRange ← INT(RAND(3)) + 1 // 1 to 3
- [6] (a) CASE OF ThisRange
- [6] (a) 1: ThisChar ← CHR(INT(RAND(26) + 65)) // 65 to 90: 'A' to 'Z'
- [6] (a) ThisChar← LCASE(ThisChar) // 'a' to 'z'
- [6] (a) 2: ThisChar ← CHR(INT(RAND(26) + 65)) // 65 to 90: A to Z
- [6] (a) 3: ThisChar ← NUM_TO_STR(INT(RAND(10)) // '0' to '9'
- [6] (a) ENDCASE
- [6] (a) RETURN ThisChar
- [6] (a) ENDFUNCTION
- [6] (a) Mark as follows: 1 Generation of any integer random number
- [6] (a) Mark as follows: 2 Randomly decide which of the three ranges to select
- [6] (a) Mark as follows: 3 Selection structure based on range
- [6] (a) Mark as follows: 4 One alphanumeric character range correct
- [6] (a) Mark as follows: 5 All alphanumeric character ranges correct
- [6] (a) Mark as follows: 6 Return ThisChar, following a reasonable attempt to generate a character in each range
- [7] (b) FUNCTION FindPassword (Name: STRING) RETURNS STRING
- [7] (b) DECLARE Index : INTEGER
- [7] (b) DECLARE Password : STRING
- [7] (b) Password ← ""
- [7] (b) Index ← 1
- [7] (b) WHILE Password = "" AND Index <= 500
- [7] (b) IF Secret[Index, 1] = Name THEN
- [7] (b) Password ← Decrypt(Secret[Index, 2])
- [7] (b) ELSE
- [7] (b) Index ← Index + 1
- [7] (b) ENDIF
- [7] (b) ENDWHILE
- [7] (b) IF Password = "" THEN
- [7] (b) OUTPUT "Domain name not found"
- [7] (b) ENDIF
- [7] (b) RETURN Password
- [7] (b) ENDFUNCTION
- [7] (b) Mark as follows: 1 Declare all local variables used, attempted solution has to be reasonable
- [7] (b) Mark as follows: 2 Conditional loop while not found and not end of array
- [7] (b) Mark as follows: 3 Compare value of element in column 1 with parameter passed into function
- [7] (b) Mark as follows: 4 ...and use Decrypt() with element in column 2 as parameter
- [7] (b) Mark as follows: 5 ...use the return value of Decrypt()
- [7] (b) Mark as follows: 6 Output warning message if parameter not found
- [7] (b) Mark as follows: 7 Return STRING value
- [3] (c) One mark for the name, one for the description
- [3] (c) Name: Stub testing
- [3] (c) Description: A simple module is written to replace each of the modules.
- [3] (c) Description: The simple module will return an expected value // will output a message to show they have been called
- [2] (d) Accept one example of a valid password to Max 2
- [2] (d) One mark for each password example that breaks one of the rules due to: Length too long // length too short
- [2] (d) One mark for each password example that breaks one of the rules due to: Invalid character
- [2] (d) One mark for each password example that breaks one of the rules due to: Incorrect grouping (including number of hyphens)
- [2] (d) One mark for each password example that breaks one of the rules due to: Duplicated characters
- [3] (e) One mark for each part: Generate a random integer divisible by 3
- [3] (e) One mark for each part: Split range into 1/3 and set as numeric
- [3] (e) One mark for each part: Else alphabetic character
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →