Please enable JavaScript to use CodeHS

Sample B No Scoring

By David Burnham

Part 2: Video

Part 3: Written Response


3A.

Provide a written response that does all three of the following: 

i. Describes the overall purpose of the program

ii. Describes what functionality of the program is demonstrated in the video

iii. Describes the input and output of the program demonstrated in the video




The purpose of this program is to take a word or phrase and encrypt it using a Caesar Cipher. The video demonstrates the user entering a phrase in and the encrypted phrase being printed out. In the video, you can see 2 different inputs. The first input is the un-encrypted phrase and the second input is the number of characters to shift the letters. You can also see the program output the encrypted phrase.


3B.

Capture and paste two program code segments you developed during the administration of this task that contain a list (or other collection type) being used to manage complexity in your program.

i. The first program code segment must show how data have been stored in the list. 

ii. The second program code segment must show the data in the same list being used, such as creating new data from the existing data or accessing multiple elements in the list, as part of fulfilling the program’s purpose. 

Then, provide a written response that does all three of the following:

iii. Identifies the name of the list being used in this response

iv. Describes what the data contained in the list represent in your program

v. Explains how the selected list manages complexity in your program code by explaining why your program code could not be written, or how it would be written differently, if you did not use the list 





First code segment:

word.push(encryptedResult);


Second code segment:

println(word[1]);


The code uses the list word. The list stores the two words that are used by the program. The first entry in the list is the unencrypted word and the second entry is the encrypted word.


The list helps manage complexity because it allows both the un-encrypted word and the encrypted word to be stored in a single variable that is accessible in both the main program to print the results and the function to encrypt the word. If the program did not use a list, it would be more complicated because the values would have to be passed back and forth with the function.


3C.

Provide a written response that does all three of the following:

i. Describes two calls to the procedure identified in written response 3c. Each call must pass a different argument(s) that causes a different segment of code in the algorithm to execute.

ii. Describes what condition(s) is being tested by each call to the procedure

iii. Identifies the result of each call



Capture and paste two program code segments you developed during the administration of this task that contain a student-developed procedure that implements an algorithm used in your program and a call to that procedure.

i. The first program code segment must be a student-developed procedure that:

• Defines the procedure’s name and return type (if necessary)

• Contains and uses one or more parameters that have an effect on the functionality of the procedure

• Implements an algorithm that includes sequencing, selection, and iteration

ii. The second program code segment must show where your student-developed procedure is being called in your program.

Then, provide a written response that does both of the following:

iii. Describes in general what the identified procedure does and how it contributes to the overall functionality of the program

iv. Explains in detailed steps how the algorithm implemented in the identified procedure works. Your explanation must be detailed enough for someone else to recreate it.



First code segment:

function encrypt(key)
{
    var encryptedResult = "";
    
    for(var i = 0; i < word[0].length; i++)
    {
        // Get the character in the original message
        var originalCharacter = word[0].charAt(i);
        
        var alphabeticIndex = ALPHABET.indexOf(originalCharacter);
        if(alphabeticIndex >= 0)
        {
            // Compute new index
            var newIndex = alphabeticIndex + key;
            newIndex = newIndex % ALPHABET.length;
            
            // Get the new character
            var newCharacter = ALPHABET.charAt(newIndex);
            
            // Add the new shifted character to the encrypted result
            encryptedResult += newCharacter
        }
        
        // Otherwise we'll keep the original character
        else
        {
            encryptedResult += originalCharacter;
        }
    }
    
    word.push(encryptedResult);
}


Second code segment:

encrypt(shift);


The included function, encrypt, takes an unencrypted word and decrypts it using a Caesar Cipher. This contributes to the overall program execution by performing the encryption on a given word and then storing that word in the word list so that the main program can print out the decrypted word.


The function does this by taking the amount to shift the letters as an input parameter. It then shifts every letter to get the encrypted result.


3D.

The two test cases are based on different shift amounts that are input for the same word. In the first case, Hello was entered and the shift was 5. For this test case, the encrypt function will take each letter and shift it over by 5 places. The result from this was MJQQT. The second call used the word Hello again, but this time shifted the letter 20 places. By shifting the letters 20 places, it causes the letters to wrap around and the results is BYFFI.