MIS 3371 Summer 2014 Parks Exam 1 Answers

Top 10,000 Passwords
from:
xato.net/passwords/more-top-worst-passwords
(with 129 obscenities removed)


This is the DIV with id=p1_out
1. (50 points)The textarea shown to the left is named ta in a form named f1. It contains the top 10,000 passwords in order of frequency of use -- each followed by a comma (except the last one). When the "Execute p1" button is clicked the javascript function p1 is executed. This function:
  1. has two arrays:
    1. an array named cbytes with 20 elements, initialize the elements of this array to zero. This array will be used to count the number of passwords with length: 0,1,2,3,...,18,19
    2. an array named cnumb with 20 elements, initialize the elements of this array to zero. This array will be used to count the number of passwords with of length: 0,1,2,3,...,18,19 that contain ONLY numbers
  2. retrieve the data from the textarea ta.
  3. split the data from step 2 into an array named a.
  4. for each password: determine its length, add one to the appropriate location in the array cbytes (e.g., if the length of the password is 6 bytes, add 1 to the value of cbytes[6])
  5. also, for each password: determine whether or not the password is composed of only the digits 0 thru 9. If the password is all digits add one to the value of cnumb for the length of the password (e.g., if the password is 7 bytes long AND contains only digits, add 1 to cnumb[7])
    (Hint: if isNAN(password string) is true, the password contains at least one byte that is NOT a digit; if false the password is composed of digits only).
  6. create a 20 row - three column table (Do not write the heading as shown in the answer). This table has 20 rows and 3 columns:
    1. column 1 contains the password length (zero thru 19).
    2. column2 shows the number of passwords with the length shown in column 1.
    3. column 3 shows the number of passwords whose length is shown in column 1 and that has ONLY digits.
  7. place the resulting table in the DIV block with id="p1_out".
Show NO HTML. Show only the javascript for the function p1.
All the Words
http://www.infochimps.com/datasets/word-list-100000-official-crossword-words-excel-readable/

This is the DIV with id=p2_out
2. (50 points) The textarea shown to the left is named ta2 and is in a form named f2. It contains a list of 113,808 English words in alphabetical order. The words are separated by commas -- except: 25 "*" characters are used to separate the words when the first letter changes (e.g., the last word that begins with an "a" is followed by a "*" not a ","; the last word that begins with a "b" is followed by a "*" not a ","; etc. The last word in the list is NOT followed anything). The button labelled "Execute p2" causes a javascript function named p2 to be executed. This function produces a 26 row - 4 column table:
  1. in column 1 place one of the 26 beginning letters: a → z. Assume the following 26 element array is stored in p2:
    var alphabet = new Array ("a","b","c", ... ,"z");
  2. in column 2 place the count of words that begin with the specified letter
  3. in column 3 place the percent of words that begin with the specified letter
  4. in column 4 place a bar graph (made from the single pixel file "green1x1.gif' representing the relative percentage of the words from column 3. The maximum bar length is 400 pixels and all bars are 15 pixels tall.
  5. after the table, report the total number of words
Algorithmically:
  1. use one of the 26 letters from the alphabet array for the value in column 1 (a → z)
  2. retrieve the textarea
  3. split the above on the "*" character into an array named alist
  4. for each alist element, split the array elements on the "," into an array named temp, store the lengths of temp in an array named listc (the 26 listc values go in column 2)
  5. sum the values of listc to obtain the total number of words -- call this total: tw
  6. for each letter, calculate the % of words that begin with that letter, store the result in an array named pcw
    (i.e., pcw[i] = listc[i] / tw * 100.0 ). These values go in column 3.
  7. Find the maximum value in pcw -- call this maxp. In column 4, place a graphic image (green1x1.gif) that is 15 pixels tall. Calculate the width of the image for each row by:
    width = 400 * pcw[i] / maxp.

Show NO HTML. Show only the javascript for the function p2.

Enter a password to see if it is on the p1 list:
  

Enter a word to see if it is on the p2 list: