hash

HashCode. How to use it.

Hi, Although I understand very well what HashCode is and what a Hash Table does, I have to admit I don´t know how to use it (Beyond a common dictionary). I wanted to implement my own Hash Table so first I want to know the very basic about Hash: I know I can get the hash code with getHashCode()/hashCode() in Java and Scala. How is this...

Is auto-initialization of multi-dimensional hash array possible in Ruby, as it is in PHP?

I am so used to work in PHP with multi-dimensional arrays, where I can assign and initialize a hash by unset($a); // just to show that there is no variable $a $a['settings']['system']['memory'] = '1 Gb'; $a['settings']['system']['disk space'] = '100 Gb'; Is there a way to do similar thing in Ruby? Or I need to initialize all dimension...

How to update a Ruby hash item inside of a loop over that hash?

I am migrating my PHP code to Ruby and at some point I need to update hash elements inside of a loop. For example: compositions.each_pair do |element,params| params['composition'].each_pair do |item,data| data['af'] /= params['af sum'] data['mf'] /= params['mass'] end end I could make it using item indexes, but it will be...

Validate passwords with CakePHP 1.3

How do I run validation checks on a password field in CakePHP, seeing that the password is hashed before I get a chance to run any checks on it? ...

Can a deterministic hashing function be easily decrypted?

Possible Duplicates: Is it possible to decrypt md5 hashes? Is it possible to reverse a sha1? i asked this question: http://stackoverflow.com/questions/3143693/working-with-huge-spreadsheet and got a great answer and i followed the advice. i used this: http://splinter.com.au/blog/?p=86 and i hashed about 300,000 different e...

calculating which strings will have the same hash

with SHA-1 is it possible to figure out which finite strings will render equal hashes? ...

Sort an array of hashes by a value in the hash

Hello, this code is not behaving as I would expect: # create an array of hashes sort_me = [] sort_me.push({"value"=>1, "name"=>"a"}) sort_me.push({"value"=>3, "name"=>"c"}) sort_me.push({"value"=>2, "name"=>"b"}) # sort sort_me.sort_by { |k| k["value"]} # same order as above! puts sort_me I'm looking to sort the array of hashes by ...

family of binary hash functions

Hi, I am looking for a family of hash function F1,..Fn, where each Fi maps any key in [0,1]. My first implementation was Fi(k) = F(k,i) = hash(i,hash(k,0)),. Here hash is the hashlittle function provided here (http://burtleburtle.net/bob/c/lookup3.c). I haven't looked under the hood of what exactly hashlittle does. As sharp readers wou...

Does sha-1 ever produce collisions for input messages less than 160bits?

I have a 128bit ID that I want to perform a one way hash on, but I don't want to ever get the same digest for an input message. Does anyone know if sha-1, or an alternative, is guaranteed not to produce collisions for the set of messages less than its output digest size? This is at least theoretically possible... I also considered using...

Multiple initialization of auto-vivifying hashes using a new operator in Ruby

I would like to initialize several auto-vivifying hashes by one-line expression. So far I came to an extra method for the AutoHash object: class AutoHash < Hash ... def few(n=0) Array.new(n) { AutoHash.new } end which allows me to do the following a, b, c = AutoHash.new.few 3 However, I feel that one can make the followin...

How to copyright the source?

It is in an area, about which I don't now anything, but it's very important, I think. Just now, I'm finishing the script of big portal. But how can I be sure that the client will not use my script in other sites? Are there any script hash algorithms? Please help me to understand how can I protect me, and my script... ...

Ruby: This "Double dimensional hash" requires processing

I have this: h = { 1 => { 1 => {:a => "x", :b => "y", :c => "z"}, 2 => {:a => "xx", :b => "yy", :c => "zz"} }, 2 => { 1 => {:a => "p", :b => "q", :c => "r"}, 2 => {:a => "pp", :b => "qq", :c => "rr"} } } I want to get this: result = { 1 => { 1 => {:a => "x"}, ...

How to handle combination []+= for auto-vivifying hash in Ruby?

In order to implement auto-vivification of Ruby hash, one can employ the following class class AutoHash < Hash def initialize(*args) super() @update, @update_index = args[0][:update], args[0][:update_key] unless args.empty? end def [](k) if self.has_key?k super(k) else AutoHash.new(:update => self, :u...

Hashing Using SHA1

Hi, I am doing an enhancement on our system and there is this other application that is already doing the hashing / ecryption but nobody knows what algorithm was used and we do not have access to the code. I have to do the same hashing using java or javascript for our system because I need to perform a search so I need to pass the corre...

How to generate a hash string with some special rules in PHP?

I'm working on a project where I need to use some hash function to make a hash string. This hash string should be unique consists of 6 to 13 characters (fixed length). I use a database to store data, so for each record, I have a unique ID. I want to use this unique ID to make a hash string ( to achieve uniqueness of resulted hash string...

how to convert a ruby hash object to JSON

How to convert a ruby hash object to JSON? So I am trying this example below & it doesn't work? I was looking at the RubDoc and obviously Hash object doesn't have a to_json method. But I am reading blogs, that Rails supports active_record.to_json and it also supports hash#to_json. I can understand ActiveRecord is a Rails object, but Has...

In Perl, what is the difference between if (%hash) and if (defined %hash)?

What is difference between if (%hash) and if (defined %hash)? my %hash ; if ( %hash) { print "defined "; } if (defined %hash) { print "defined "; } ...

Continuing a SHA1 hash in PHP

Is it possible to "continue" a hash in PHP? Say for example I start hashing a large chuck of data like this: $ctx = hash_init('sha1'); hash_update($ctx, $data_block); $hash = hash_final($ctx); That's all well and good but suppose the data is not fully available at that point and I want to "pause" the hashing mid-way and save where we'...

Which hash function can this be?

I have some strings and some hashes of them, but I don't know which hash function is used. Any idea? String hash NN34W f8b46bcdc3b3c92 EM3M3 d8015ca876fd051 HXDKD a740e97464e5dfe AKREJ aa7aa2dadfcbe53 3bNMK 0f11440639191d9 Edit: Thank for answers, it's a hash of the captcha. https://registracia.azet.sk/ If yo...

Commutative, accumulator-based function for calculating a digest of multiple hashes

I'm writing something that summarizes the files in a file system by hashing a sample of their contents. It constructs a tree of directories and files. Each file entry has the hash of the file contents. For each directory entry, I want to store a hash of the contents of all files in the directory, including those in sub-directories - I'll...