Hashing

Assignment 10B

by Alan Harris

HTML

Hashing Algorithm is from http://www.webtoolkit.info/javascript-sha1.html#.WsEjI4jwaM9<br><br>
<label>Add password: </label>

<input type="text" id="nodeinput" value="something">

<button onclick="addNode();">
Sumbit
</button><br>

<label>Check password:</label>
<input type="text" id="searchinput" value="something">
<button onclick="search();">
Sumbit
</button><br><br>
<button onclick="clearScreen();">
Clear List and Screen
</button>
<div id="print"></div>

CSS

button:focus {
  border: 1px solid black;
  padding: 4px 4px;
}

button {
    background-color: grey;
    border: 1px solid black;
    color: white;
    padding: 4px 8px;
    text-decoration: none;
    margin: 4px 2px;
    }
 button:hover {
   background-color:black;
 }

JavaScript

var ANode = new Node();
var aList = new List1();

function Node(input) {
//	this.id = null;
  this.content = input;
  this.next = null;
  this.last = null;
  return this;
}  

function List1(input) {
	this.head = new Node(input);
  this.length = 1;
  this.last = this.head;
  return this;
}
List1.prototype.add = function(ANode) {
	var element = new Node();
  element.content = ANode;
  
	if (this.head == null){
  	this.head = element;
    this.length = 1;
    return element;
  }
  if (this.tail == null) {
  	this.tail = element;
    this.tail.prev = this.head;
    this.head.next = this.tail;
    this.length++;
    return element;
  }
  this.tail.next = element;
  element.prev = this.tail;
  this.tail = element;
  return element;
}

List1.prototype.print = function() {
	if (this.head == null) {
		return "List is Empty."
	}
  var p = "";
  var aNode = this.head;
  while(aNode != null) {
  	p += aNode.content + "	";
    aNode = aNode.next;
  }
  return p;
}
List1.prototype.clear = function() {
	this.head = null;
  this.tail = null;
  this.length = 1;
  this.next = null;
  this.last = null;
}

List1.prototype.search = function() {
	var e = this.head;
  while(e != null) {
  	 var t = e.content;
     e = e.next;
  }
  	return t;
  }



function clearScreen() {
	var c = "";
  List1.prototype.clear();
  document.getElementById("print").innerHTML = c;
  
}

function addNode() {
	var input = document.getElementById("nodeinput").value;
 // SHA1(input);
 // document.getElementById("print").innerHTML = SHA1(input);
 document.getElementById("print").innerHTML = "Adding password!"
  List1.prototype.add(SHA1(input));
  
//  document.getElementById("print").innerHTML = List1.prototype.print();
}


function search() {

	var s_Input = document.getElementById("searchinput").value;
  var c = "";
  
  if (SHA1(s_Input) == List1.prototype.search()) {
  	c += "Password exists";
    document.getElementById("print").innerHTML = c;
  }
  else {
  	c += "Password does not exist" + "</br>";
  ...