// Hashing Function
function simpleHash(str) {
len = str.length;
hash = 0;
for (i = 1; i <= len; i++) {
char = str.charCodeAt((i - 1));
hash += char * Math.pow(31, (len - i));
hash = hash & hash;
}
return hash;
}
// Linked list
function LinkedList() {
this.head = null;
this.tail = null;
this.length = 0;
}
function Node(element) {
this.next = null;
this.prev = null;
this.item = element;
}
LinkedList.prototype.add = function(info) {
var node = new Node();
node.item = info
if (!this.head) {
this.head = node;
this.tail = node;
}
else
{
node.previous = this.tail;
this.tail.next = node;
this.tail = node;
}
this.numberOfValues++;
}
var list = new LinkedList();
// Adding the password to list
function addAPassword() {
var c = document.getElementById("addPass").value;
c = simpleHash(c);
list.add(c);
list.length++;
alert(c);
}
// Checking the list for the added password
function checkForPassword() {
var check = document.getElementById("checkPass").value;
check = simpleHash(check);
alert(check);
alert(list.length);
var len = list.length;
// Searching for passwords if found report if not found report
var node = list.head;
for(var i =0; i < len; i++){
alert(node.item);
if (check == node.item){
alert("Password Found");
return;
}
else
{
node = node.next;
}
}
alert("Password Not Found");
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.