Skip to main content
A-LevelComputer ScienceProgramming9618/21 · May/June 2022 · Q821 Marks

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

  1. (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]
  2. (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]
  3. (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]
  4. (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]
  5. (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.

  1. [6] (a) FUNCTION RandomChar() RETURNS CHAR
  2. [6] (a) DECLARE ThisRange : INTEGER
  3. [6] (a) DECLARE ThisChar : CHAR
  4. [6] (a) //First select the range
  5. [6] (a) ThisRange ← INT(RAND(3)) + 1 // 1 to 3
  6. [6] (a) CASE OF ThisRange
  7. [6] (a) 1: ThisChar ← CHR(INT(RAND(26) + 65)) // 65 to 90: 'A' to 'Z'
  8. [6] (a) ThisChar← LCASE(ThisChar) // 'a' to 'z'
  9. [6] (a) 2: ThisChar ← CHR(INT(RAND(26) + 65)) // 65 to 90: A to Z
  10. [6] (a) 3: ThisChar ← NUM_TO_STR(INT(RAND(10)) // '0' to '9'
  11. [6] (a) ENDCASE
  12. [6] (a) RETURN ThisChar
  13. [6] (a) ENDFUNCTION
  14. [6] (a) Mark as follows: 1 Generation of any integer random number
  15. [6] (a) Mark as follows: 2 Randomly decide which of the three ranges to select
  16. [6] (a) Mark as follows: 3 Selection structure based on range
  17. [6] (a) Mark as follows: 4 One alphanumeric character range correct
  18. [6] (a) Mark as follows: 5 All alphanumeric character ranges correct
  19. [6] (a) Mark as follows: 6 Return ThisChar, following a reasonable attempt to generate a character in each range
  20. [7] (b) FUNCTION FindPassword (Name: STRING) RETURNS STRING
  21. [7] (b) DECLARE Index : INTEGER
  22. [7] (b) DECLARE Password : STRING
  23. [7] (b) Password ← ""
  24. [7] (b) Index ← 1
  25. [7] (b) WHILE Password = "" AND Index <= 500
  26. [7] (b) IF Secret[Index, 1] = Name THEN
  27. [7] (b) Password ← Decrypt(Secret[Index, 2])
  28. [7] (b) ELSE
  29. [7] (b) Index ← Index + 1
  30. [7] (b) ENDIF
  31. [7] (b) ENDWHILE
  32. [7] (b) IF Password = "" THEN
  33. [7] (b) OUTPUT "Domain name not found"
  34. [7] (b) ENDIF
  35. [7] (b) RETURN Password
  36. [7] (b) ENDFUNCTION
  37. [7] (b) Mark as follows: 1 Declare all local variables used, attempted solution has to be reasonable
  38. [7] (b) Mark as follows: 2 Conditional loop while not found and not end of array
  39. [7] (b) Mark as follows: 3 Compare value of element in column 1 with parameter passed into function
  40. [7] (b) Mark as follows: 4 ...and use Decrypt() with element in column 2 as parameter
  41. [7] (b) Mark as follows: 5 ...use the return value of Decrypt()
  42. [7] (b) Mark as follows: 6 Output warning message if parameter not found
  43. [7] (b) Mark as follows: 7 Return STRING value
  44. [3] (c) One mark for the name, one for the description
  45. [3] (c) Name: Stub testing
  46. [3] (c) Description: A simple module is written to replace each of the modules.
  47. [3] (c) Description: The simple module will return an expected value // will output a message to show they have been called
  48. [2] (d) Accept one example of a valid password to Max 2
  49. [2] (d) One mark for each password example that breaks one of the rules due to: Length too long // length too short
  50. [2] (d) One mark for each password example that breaks one of the rules due to: Invalid character
  51. [2] (d) One mark for each password example that breaks one of the rules due to: Incorrect grouping (including number of hyphens)
  52. [2] (d) One mark for each password example that breaks one of the rules due to: Duplicated characters
  53. [3] (e) One mark for each part: Generate a random integer divisible by 3
  54. [3] (e) One mark for each part: Split range into 1/3 and set as numeric
  55. [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 →

About this question

Topic
Programming, A-Level Computer Science (syllabus 9618). Structured question, 21 marks.
Source
A-Level Computer Science, May/June 2022 Paper 2 Variant 1, question 8.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep