Assignment 10
by Kristy Bond
HTML
<form id="form">Enter Password to be hashed.
<br/>
<textarea id="phrase" rows="1" cols="20"></textarea>
<br/>
<input type="button" value="Search Hash" onClick=hashPhrase();>
<input type="button" value="Add Hash" onClick=pushphrase();>
<input type="button" value="Remove hash" onClick=popPhrase();>
</form>
<br/>
<div id="output"></div>
JavaScript
//Once you have a list and a hash function – we will use it to create a Password System.
//Your interface will include 2 Text boxes;
//Add Password To List [ Text input ] Submit
//Check For Password [ Text Input ] Submit
//The first submit will Add the HASHED version of the Password as a Node in your list.
//The second submit will Hash the second text box and compare it against all the values in the list. If it is in the List you will Output “Password Found” if it is not in the list output “Not Found”
var hashTable = new HashTable();
function parsePhrase() {
hashTable.clear();
var phrase = document.getElementById("phrase").value;
var phraseAsStringArray = phrase.split(" ");
var len = phraseAsStringArray.length;
for (var i = 0; i < len; i++) {
hashTable.addWord(phraseAsStringArray[i], i + 1);
}
document.getElementById("output").innerHTML = hashTable.print();
}
function HashTable(obj) {
this.bins = {};
this.length = 0;
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
this.bins[p] = obj[p];
this.length++;
}
}
this.addWord = function(word, index) {
if (this.hasWord(word)) {
this.addExistingWord(word, index);
}
else {
this.addNewWord(word, index);
}
return word;
}
this.hasWord = function(word) {
return this.bins.hasOwnProperty(word);
}
this.addNewWord = function(word, index) {
this.bins[word] = index;
this.length++;
return word;
}
this.addExistingWord = function(word, index) {
var current = this.bins[word];
this.bins[word] = current + " " + index;
return word;
}
this.print = function() {
var str = "";
for (var w in this.bins) {
if (this.hasWord(w)) {
str = str + w + ": " + this.bins[w] + "<br/>";
}
}
return str;
}
...