A program allows a user to save passwords used to log in to websites. A stored password is then inserted automatically when the user logs in to the corresponding website. 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] "thiswebsite.com" Secret [27, 2] "............" Secret [28, 1] "thatwebsite.com" Secret [28, 2] "............" Note: • For security, the passwords are stored in an encrypted form, shown as "............" in the example. • The passwords cannot be used without being decrypted. • You may assume the encrypted form of a password will NOT be an empty string. The programmer has started to define program modules as follows: Module Description Exists() • Takes two parameters: ○ a string • a character • Performs a case-sensitive search for the character in the string • Returns TRUE if the character occurs in the string, otherwise returns FALSE 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 Note: in a case-sensitive comparison, 'a' is not the same as 'A'.
- (a)Write pseudocode for the module Exists().[5]
- (b)A new module SearchDuplicates () will: • search for the first password that occurs more than once in the array and output a message each time a duplicate is found. For example, if the same password was used for the three websites ThisWebsite.com, website27.net and websiteZ99.org, then the following messages will be output: "Password for ThisWebsite.com also used for website27.net" "Password for ThisWebsite.com also used for websiteZ99.org" • end once all messages have been output. The module will output a message if no duplicates are found. For example: "No duplicate passwords found" Write efficient pseudocode for the module SearchDuplicates(). Encrypt() and Decrypt() functions have been written. Note: It is necessary to decrypt each password before checking its value.[8]
- (c)A password has a fixed format, consisting of three groups of four alphanumeric characters, separated by the hyphen character '-'. An example of a password is: "FxAf-3haV-Tq49" Each password must: • be 14 characters long • be organised as three groups of four alphanumeric characters. The groups are separated by hyphen characters • not include any duplicated characters, except for the hyphen characters. An algorithm is needed for a new function GeneratePassword(), which will generate and return a password in this format. Assume that the following modules have already been written: Module Description Exists() • Takes two parameters: ○ a string • a character • Performs a case-sensitive search for the character in the string • Returns TRUE if the character occurs in the string, otherwise returns FALSE RandomChar() • Generates a single random character from within one of the following ranges: o 'a' to 'z' • 'A' to 'Z' • '0' to '9' • Returns the character Note: in a case-sensitive comparison, 'a' is not the same as 'A'. Describe the algorithm for GeneratePassword(). Do not use pseudocode statements in your answer.[6]
Mark scheme
Marking points from the official mark scheme (May/June 2022). The mark or mark type is shown in brackets.
- [5] Marks as follows (Conditional loop solution):
- 1 Conditional loop while character not found and not end of string
- 2 Extract a char in a loop
- 3 Compare with parameter without case conversion in a loop
- 4 If match found, set termination logic in a loop
- 5 Return BOOLEAN value
- ALTERNATIVE (Using Count-controlled loop):
- [5] Marks as follows (Count-controlled loop variant):
- 1 Loop for length of ThisString (allow from 0 or 1)
- 2 Extract a char in a loop
- 3 Compare with parameter without case conversion in a loop
- 4 If match found, immediate RETURN of TRUE
- 5 Return FALSE after the loop // Return Boolean if no immediate RETURN
- [8] Marks as follows to Max 8:
- 1. (Any) conditional loop...
- 2. ... from 1 to 499 while (attempt at) no duplicate
- 3. Skip unused password
- 4. Use Decrypt() and assign return value to ThisPassword
- 5. Inner loop from outer loop index + 1 to 500 searching for duplicates
- 6. Compare ThisPassword with subsequent passwords (after use of Decrypt())
- 7. If match found, set outer loop termination
- 8. and attempt an Output message giving duplicate
- 9. Output 'No duplicate passwords found' message if no duplicates found after the loop
- [6] One mark for each point that is referenced:
- 1 Initialise password to empty string at the start and return (attempted) password at the end of the function
- 2 Two loops to generate 3 groups of 4 characters // One loop to generate 12 / 14 characters
- 3 Use of RandomChar () to generate a character in a loop
- 4 Reject character if Exists() returns TRUE, otherwise form string in a loop
- 5 (Attempt to) use hyphens to link three groups
- 6 Three groups of four characters generated correctly with hyphens and without duplication (completely working algorithm)
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 →