A great hash function to generate passwords with I made a while ago!
NPC Code:
function onCreated() {
this.hashtable = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWyYz Z132465798";
this.symbols = ".,/*-+!#¤%&/()=?`´}][{$£@|øæåØÆÅéáí[DèàìêâîôòóõñãöëäÖËÄÏïÂÎÛÔÊÑÕ(hÃZÁCÓÍÚÉTÌÙÒÈ<>";
}
function hash(string, key, length) {
temp.table = new[length];
temp.htl = this.hashtable.length();
for(temp.i = 0; i < length; i ++) {
temp.output = 0;
for(temp.j = 0; j < string.length(); j ++) {
for(temp.k = 0; k < key.length(); k ++) {
temp.char1 = string.charat(j>>1);
temp.char2 = key.charat(k);
temp.check = this.symbols.pos(char1);
if (check > -1) char1 = this.hashtable.charat(check)%htl;
check = this.symbols.pos(char2);
if (check > -1) char2 = this.hashtable.charat(check)%htl;
temp.pos = {
this.hashtable.pos(char1),
this.hashtable.pos(char2)
};
temp.b = pos[0] >> 16;
b = (b%length) << i;
b += (int((i*length)-k)%pos[1]) + int((length^(i+j)+k)/pos[0]);
b %= htl;
output += b xor pos[1];
}
output += length/i;
output %= htl;
}
table[i] = this.hashtable.charat(output);
}
temp.out = "";
for(temp.c : table) {
out @= c;
}
return out;
}
This is a hash function I made way back, and it's pretty effective, and length of string & key can be as long as you want (longer string lengths requires more processing though) and it allows you to specify the length of the returned hash.
You might find something in there, I would suggest to take a look at bit manipulations, xor, etc and of course, do as Chris said and check out other encryption and hash functions out there.
Example output:
PHP Code:
function onCreated() {
echo(hash("foo", "bar", 8)); // FrvUqQuU
echo(hash("Hi there, I'm Chompy", "key", 8)); // lCAP4FFy
echo(hash("Hi there, I'm Chompy", "key", 6)); // YkI6IL
echo(hash("baz", "bar", 24)); // 3hBPVspQmuKQ1PrAvuG4FmdL
echo(hash("foo", "foo", 10)); // 4KjCpuokgC
}