hash

Cryptographic hash (sha1 or md5) of data given as a string in Mathematica

The sha1 hash of "abc" is a9993e364706816aba3e25717850c26c9cd0d89d The only way to get Mathematica to tell you that with its Hash function is Hash[abc, "SHA"] // IntegerString[#, 16]& (The IntegerString thing is just to output it in hex like most implementations do.) Note that Hash["abc", "SHA"] gives the hash of "\"abc\"" ...

ruby hash with self referencing elements / recursive hash

I need a ruby hash H with keys :a, :b, :c so that H[:b] = H[:a] + 1; H[:c] = H[:b] + 2 etc. How can I define such a hash in a one line declaration, like H = {:a=>1, :b => H[:a] + 1, :c => H[:b] +2, ... } ? I need something similar to DataMapper properties declaration: property :path, FilePath property :md5sum, String, :default => ...

Translating algorithm/code from Ruby to PHP

digest = HMAC.digest(Digest.new(SHA1), Base64.decode64(key), HashString) return Base64.encode64(digest.to_s()).chomp() What would the above be in PHP? ...

Filter an array of hashes within a hash in ruby/rails

I'm aggregating RSS feeds using FeedTools. I followed this tutorial: http://simonwoodside.com/weblog/2008/12/7/ruby%5Fon%5Frails%5Ffeedrss%5Faggregator/ and everything functioned fine. The problem is I want to filter some of the hashes that exist within the array [:items] from inside the parsed feed hash. Here's the RSS cached feed obj...

Order a list of files by size via python

Example dump from the list of a directory: hello:3.1 GB world:1.2 MB foo:956.2 KB The above list is in the format of FILE:VALUE UNIT. How would one go about ordering each line above according to file size? I thought perhaps to parse each line for the unit via the pattern ":VALUE UNIT" (or somehow use the delimiter) then run it throug...

Getting Ruby code to work, creating SHA1 hash from given string and key

I have a small code snippet that I'm trying to get to work in Ruby. digest = HMAC.digest(Digest.new(SHA1), Base64.decode64(key), HashString) return Base64.encode64(digest.to_s()).chomp() I tried it as follows: hashstring = "POST application/octet-stream Thu, 05 Jun 2008 16:38:19 GMT /rest/objects date:Thu, 05 Jun 2008 16:38:19 GMT g...

What is the purpose of the "salt" when hashing?

Ok, I’m trying to understand the reason to use salt. When a user registers I generate a unique salt for him/her that I store in DB. Then I hash it and the password with SHA1. And when he/she is logging in I re-hash it with sha1($salt.$password). But if someone hacks my database he can see the hashed password AND the salt. Is that hard...

Which hash function is currently a good choice for passwords?

Hi, Some hash functions are today not as safe as they were some years ago. Which hash function would currently be a good choice for hashing passwords? Thanks in advance. ...

C# getting unique hash from all objects

Hi I want to be able to get a uniqe hash from all objects. What more, in case of Dictionary<string, MyObject> foo I want the unique keys for: string MyObject Properties in MyObject foo[someKey] foo etc.. object.GetHashCode() does not guarantee unique return values for different objects. That's what I need. Any idea? Thank y...

g++ linker error: Getting undefined reference error for std::hash

Hi, I'm using the unordered_map of TR1 implementation in my code and the linker gives weird errors I cannot even decipher: BPCFG.o: In function `std::__detail::_Hash_code_base<DottedRule, std::pair<DottedRule const, int>, std::_Select1st<std::pair<DottedRule const, int> >, eqDottedRule, std::hash<DottedRule>, std::__detail::_Mod_rang...

Email Hashes on Facebook

I have a question about email hash on facebook if the email address has been changed by the facebook user. My site stored the email hash to match with the facebook email hash to identify the user on our website is the same user on our facebook application. If a facebook user has two facebook account with different email address, and o...

Why do I need asterisk before an array?

I have no idea if this is a Hash issue or an Array issue, but I don't figure out why asterisk (*) sign is required in the third example to get a hash filled with data. Without it, it outputs an empty hash. # -*- coding: utf-8 -*- require 'pp' pp [[:first_name, 'Shane'], [:last_name, 'Harvie']] # => [[:first_name, "Shane"], [:last_name, ...

Turn of Cakephp Auth password hashing.

I am upgrading a cakephp app at my new job from l.1 to 1.2. I am replacing the homegrown 1.1 authorization code with the great Auth component. The problem is that the passwords are not hashed in the legacy DB. How can I turn off the password hashing temporarily so I can start using the Auth component. Don't worry, I will hash the passwo...

Programatically changing hash of a file without corrupting it

Does anyone have any info on changing the hash of a file without corrupting it? I read about appending a null byte to the end of the file, thus changing the MD5 without corrupting it. Anyone have any info? The language I wish to do this in is PHP. Thanks. ...

Hash table faster in C# than C++?

Here's a curiosity I've been investigating. The .NET Dictionary class performs ridiculously fast compared to the STL unordered_map in a test I keep running, and I can't figure out why. (0.5 seconds vs. 4 seconds on my machine) (.NET 3.5 SP1 vs. Visual Studio 2008 Express SP1's STL) On the other hand, if I implement my own hash table i...

Populate ruby Array1 with Array2 String element if and only if Array2 element matches Hash value(not key).

I have a ruby hash: VALS = { :one => "One", :two => "Two" } and an Array: array2 = ["hello", "world", "One"] Question: How can I populate a new array1 so that it only pulls in any values in array2 that match exactly the values in VALS? For example, I have tried: array2.each_with_index do |e,i| array1 << e if VALS[i] ~= e end Alon...

Ruby Array Intersection, Hash.has_value? for intersection with array[i+1] based on hash values

I am trying to populate an array with an intersection of an array and hash based on hash values: array2 = ["hi","world","One"] Vals = {:one => "One", :two => "Two"} array2 = VALS.values & array2 print array2 Works fine for intersection of hash values and array2[ i ], but if I want to instead populate with array2[ i+1 ] element from ar...

Do any common OS file systems use hashes to avoid storing the same content data more than once?

Many file storage systems use hashes to avoid duplication of the same file content data (among other reasons), e.g., Git and Dropbox both use SHA256. The file names and dates can be different, but as long as the content gets the same hash generated, it never gets stored more than once. It seems this would be a sensible thing to do in a ...

How should I be handling checksum collisions in my application?

I have a part of my application that stores files. Because we could potentially be adding many of the same file, I am first keeping a hash of each file. If two files have the same hash, then we throw out one, and both "references" to that file point to the same physical file. How much should I be worried about hash collisions? In th...

Why is CakePHP hashing my password twice?

Hi, im Using CakePHPs standard Auth mechanism, but I have some problems with that. Everytime a user logges in the password got hashed twice. I have the Auth Component in the var $componets Array in the app_controller.php and one in the var $components Array from my users_controller where the login action is defined. I have defined a ...