hashing

How to calculate the hash code of a string by hand (Java related)

Hi guys, I was wondering how to calculate the hash code for a given string by hand. I understand that in Java, you can do something like: String me = "What you say what you say what?"; long whatever = me.hashCode(); That's all good and dandy, but I was wondering how to do it by hand. I know the given formula for calculating the hash ...

Hashing sets of integers

I'm looking for a hash function over sets H(.) and a relation R(.,.) such that if A is included in B then R(H(A), H(B)). Of course, R(.,.) must be easy to verify (constant time), and H(A) should be computed in linear time. One example of H and R is: H(A) = OR over 1 << (h(x) % k), for x in A, k a fixed integer and h(x) a hash function...

Crating dictionary with binary search tree and hashing

I’m about to create a "smart" dictionary that could generate similar words if the word from the user is not in the dictionary. The dictionary starts with reading a file with words, the word should be added to the binary tree and a hash table. The hash table is used to determine if the word or similar word is in the dictionary, the hash ...

Evenly distributed hash function

I need a hash function that takes a few (eg. 2 or 3) unsigned integers as input, and returns a floating point value between -1 and +1. The collection of these returned values must be evenly distributed. A sequence of outputs from the function must appear to be a random sequence, even if the input numbers are sequential. Also the faster ...

how can I hash/obfuscate 9-11 chars uniquely

I have a series of codes in the format: AA12345A1 i.e.: [a-z]{2}[0-9]{5}[a-z][0-9] and AA12345A123 i.e.: [a-z]{2}[0-9]{5}[a-z][0-9]{3} I need to create a new "code" of any format from either of the above to formats to obscure the difference between the ones ending in 1 number and the ones ending in 3 numbers (this reveals inform...

Hashing to uniformly distribute value over a large range

I want to devise an algorithm which takes a set of values and distributes it uniformly over a much larger range. eg. i have 1000 values and want to distribute them over a range of value 2^16. Also, the input values can change continuously and i need to keep parsing each input value through the hash function so that it gets distributed un...

I am searching for an example in C for using pkcs#5

AFAIK, PKCS#5 is used for hashing passwords. I could not find an example to explain how to use openssl to make a client for hashing the passwords. ...

How to create a hash code in C# on object graph supplied by a WCF service.

I currently have a WCF service which provides an object graph of data on request. I want to have a mechanism where the client can compute a hash on the cached object graph it posses and can then supply this hash value to the WCF service to see if it matches the data the service possesses. I tried this using a standard cryptographic algo...

Ideal hashing method for wide distribution of values?

As part of my rhythm game that I'm working, I'm allowing users to create and upload custom songs and notecharts. I'm thinking of hashing the song and notecharts to uniquely identify them. Of course, I'd like as few collisions as possible, however, cryptographic strength isn't of much importance here as a wide uniform range. In addition, ...

Can I use a member variable as a key to a hash_set/hash_map?

Hi. I have a class like this: class Foo { long long Id; string x; string y; // other member variables and functions }; I would like to store this in a hash_set (or hash_map), but use the Id member variable as the key for inserting and searching. I'm not sure how I can do this. I thought of the following ways, but none of t...

is there any efficient way to get node by key (better than linear hashing or btree)?

Hi! I'm looking for efficient algorithm for storing and fetching data by key. I've already read about Litvin linear dynamic hash and another methods, but still, i wonder is there some way to get (search, calculate) key in VERY large binary file (consider more than 100 gb)? I'm just curios is there ANY algorithm which works without perf...

Good hash function for list of 2-d positions?

Hi! I have a series of objects whose only different internal state is a fixed-length list(or whatever) of 2-d positions (2 integers). That is, they all have the same number of elements, with (potentially) different 2-d values. I'm going to be constantly comparing new instances against all previously existent, so it's very important tha...

Sha-1 hash collision

how hard is it to find x where sha1(x) = x? where x is the form of 'c999303647068a6abaca25717850c26c9cd0d89c' i think the fact that there are sha1 collisions make this possible, but, how easy (or hard) is it to find an example? ...

Base64 Encoding safe for filenames?

Is Base64 encoding safe to use for filenames on windows and linux systems? From my research I have found replacing all "/" characters of the output string with "-" or "_" should resolve any issues. Can anyone provide more details on this? Currently in Java I am using the following peice of code: MessageDigest md5Digest = MessageDi...

hashing algorithm for strings

I came across a situation where i had to count the number of occurences of each word in a string. I decided hashing would be the best way to do it (Find the hash value for each word that is encountered and increment the count at the position indexed by the hash value - assuming i use an array). What hashing algorithm can i use to ensure...

Checking for database changes at set intervals in ASP.NET page

Hi all, I have an ASP.NET page which contains a large number of gridviews, which contain masses amount of data which take a fair while to rebind. I currently have it set so the gridviews are only bound when the account number is changed (on the page, the user searches for an account which then displays their information). I'd like it to...

how to use boost::unordered_map

hello, for my application, i need to use a hash map, so i have written a test program in which i store some instances of a baseclass in a boost::unordered_map. but i want to reach the instances by calling special functions which return a derived class of the base and i use those functions' parameters for hash key of unordered_map. if no...

Problem with hashing function - C

I am using the following hashing function provided in the K&R book. #define HASHSIZE 101 unsigned hash(char *s) { unsigned hashval; for (hashval = 0; *s != '\0'; s++) hashval = *s + 31 * hashval; return hashval % HASHSIZE; } In my project, I have more warnings turned on (warnings are treated as errors too) and the...

How to implement a good __hash__ function in python

When implementing a class with multiple properties (like in the toy example below), what is the best way to handle hashing? I guess that the __eq__ and __hash__ should be consistent, but how to implement a proper hash function that is capable of handling all the properties? class AClass: def __init__(self): self.a = None ...

Distributed LSH (locality sensitive hashing)

I want to build a large scalable database with millions of high dimensional vectors using LSH. Since I have to hold all the data in ram for fast querying, the data must be distributed onto multiple servers to hold all the objects. A naïve approach would be to spread all objects to different servers and send one query to every server. Th...