Assignment 10
by Jeremy Boss
HTML
<input type="textbox" id="passIn" />
<input type="button" value="Add Password To List" onClick="passInClick();" />
<br/>
<br/>
<input type="textbox" id="passCheckIn"/>
<input type="button" value="Check For Password" onClick="passCheckClick();"/>
<div id="out"></div>
<div id="out2"></div>
JavaScript
var stored = new aList();
function aNode(val) {
this.input = sha(val);
this.next = null;
this.last = null;
return this;
}
function aList() {
this.length = 0;
this.head = null;
this.tail = null;
}
aList.prototype.add = function(val) {
var bNode = new aNode(val);
if (this.head == null) {
this.head = bNode;
this.length = 1;
return bNode;
}
else if (this.tail == null) {
this.tail = bNode;
this.tail.last = this.head;
this.head.next = this.tail;
this.length = 2;
return bNode;
}
else {
this.tail.next = bNode;
bNode.last = this.tail;
this.tail = bNode;
this.length++;
return bNode;
}
}
var sha = function(z) {
var q = 1;
var r = 0;
var s;
var t;
if (z) {
q = 0;
for (s = z.length - 1; s >= 0; s--) {
t = z.charCodeAt(s);
q = (q << 6 & 268435455) + t + (t << 14);
r = q & 266338304;
q = r !== 0 ? q ^ r >> 21 : q;
}
}
return String(q);
}
aNode.prototype.toString = function() {
return "Node: " + this.input + "<br/>";
}
aList.prototype.print = function() {
var out = "";
var bNode = this.head;
while (bNode != null) {
out += bNode.toString();
bNode = bNode.next;
}
return out;
}
function passInClick() {
var passLoc = document.getElementById("passIn").value;
stored.add(passLoc);
outList();
}
function outList() {
document.getElementById("out").innerHTML = stored.print();
}
function passCheckClick(passLoc) {
passLoc = document.getElementById("passCheckIn").value;
var checkSha = sha(passLoc);
var checkInd = stored.head;
var stringL = "";
while (checkInd != null) {
if (checkInd.input == checkSha){
stringL = "Password Found";
document.getElementById("out2").innerHTML = stringL;
return stringL;
}
checkInd = checkInd.next;
}
stringL = "Not Found";
document.getElementById("out2").innerHTML = stringL;
return stringL;
}