hash

Why do these two files hash to the same value when I use MemoryStream?

Hello, I'm writing a c# routine that creates hashes from jpg files. If I pass in a byte array to my SHA512 object then I get the expected behavior, however, if I pass in a memory stream the two files always hash to the same value. Example 1: SHA512 mySHA512 = SHA512.Create(); Image img1 = Image.FromFile(@"d:\img1.jpg...

How can you easily test hash equality in Ruby when you only care about intersecting keys?

Say I have the following hashes: hash_x = { :a => 1, :b => 2 } hash_y = { :b => 2, :c => 3 } I need a chunk of logic that compares the two for equality only taking into consideration intersecting keys. In this example the 'b' key is the only commonality between the two hashes and it's value is set to '2' in both so by that ...

What is the probability that the first 4 bytes of MD5 hash computed from file contents will collide?

This is a combinatorics question with some theory in hashing algorithms required. Let's say the input can be any random sequence of bytes 30 kB to 5 MB of size (I guess that makes quite a few combinations of input values :)) What is the probability that the first 4 bytes (or first n bytes) of a MD5 hash computed from the byte sequence ...

Make md5 strong

Im making a website that will intergrate with game that only support md5 hashing metod (atm). Which ofc is not especially safe anymore. But how could i make it stronger? Should I just generate long strings of random letters and numbers and hash them? But then the users have to save the password on a paper/txt file in computer. What do y...

Hashes in Cocoa and Objective-C

Hi, I'm writing an application for Mac. I need some code which generates a hash from a string. I need to create these hashes: MD2 MD4 MD5 SHA-0 SHA-1 How can I do this? Thanks. ...

Ruby: Make hash from Hash => Set

I have a join table that I'm using to find available services for an order form; in that table is the utility_id and a company_id. What I want is a group (hash) where the keys are the utility names and the values are hashes of the corresponding companies. I got the following... Service.find(:all).to_set.classify { |service| Utility.fi...

What is hash exactly?

Hi, I am learning MD5. I found a term 'hash' in most description of MD5. I googled 'hash', but I could not find exact term of 'hash' in computer programming. Why are we using 'hash' in computer programming? What is origin of the word?? ...

How do I convert a ruby hash to XML?

Here is the specific XML I ultimately need: <?xml version="1.0" encoding="UTF-8"?> <customer> <email>[email protected]</email> <first_name>Joe</first_name> <last_name>Blow</last_name> </customer> But say I have a controller (Rails) that is sending the data to a method, I'd prefer to send it as a hash, like so: :first_name => 'Joe...

Java: Calculate SHA-256 hash of large file efficiently

I need to calculate a SHA-256 hash of large file (or portion of it). My implementation works fine, but its much slower than the C++'s CryptoPP calculation (25 Min. vs. 10 Min for ~30GB file). What I need is a similar execution time in C++ and Java, so the hashes are ready at almoust the same time. I also tryed the Bouncy Castle implement...

compute crc of file in python

I want calculate crc of file, and get output like [E45A12AC] I don't want md5 or other. #!/usr/bin/env python import os, sys import zlib def crc(fileName): fd = open(fileName,"rb") content = fd.readlines() fd.close() for eachLine in content: zlib.crc32(eachLine) for eachFile in sys.argv[1:]: crc(eachFile) calculates for...

handling data structures (hashes etc) gracefully in ruby

I recently did a class assignment where I made a really hacky data structure. I ended up using nested hashes, which seems like a good idea, but is really hard to iterate through and manage. I was doing general stuff, like one tag maps to a hash of items that map to prices and stuff like that. But some of them were getting more complicat...

Comprehensive information about hash salts

There are a lot of questions about salts and best practices, however most of them simply answer very specific questions about them. I have several questions which feed into one another. Assuming a database is compromised a per user salt prevents the use of generic rainbow tables to crack passwords. A separate rainbow table would have ...

Is forcing complex passwords "more important" than salting?

I've spent the past 2 hours reading up on salting passwords, making sure that I understood the idea. I was hoping some of you could share your knowledge on my conclusions. Say the salts on a system are 12 characters. If i'm an attacker, I don't have to create a rainbow table of all the combinations of those 12 characters with each entr...

Making a sha1-hash of a row in Oracle

I'm having a problem with making a sha1-hash of a row in a select on an Oracle database. I've done it in MSSQL as follows: SELECT *,HASHBYTES('SHA1',CAST(ID as varchar(10)+ TextEntry1+TextEntry2+CAST(Timestamp as varchar(10)) as Hash FROM dbo.ExampleTable WHERE ID = [foo] However, I can't seem to find a similar function to use when ...

How to use sha256 in php5.3.0

Hello, I'm using sha256 to encrypt the password. I can save the sha256 encrypted password in mysql. But i can't login with the same clause. Insert code: <?php error_reporting(E_ALL ^ E_NOTICE); $username = $_POST['uusername']; $passcode = $_POST['ppasscode']; $userflag = $_POST['uuserflag']; //$passcodeen = hash('sha256',$passcode); $...

A dictionary with values that are dictionaries: trying to sum across those keys in python

Data structure is a dictionary, each value is another dictionary, like: >>> from lib import schedule >>> schedule = schedule.Schedule() >>> game = schedule.games[0] >>> game.home <lib.schedule.Team instance at 0x9d97c6c> >>> game.home.lineup {'guerv001': {'HR': 392, '1B': 1297}, 'kendh001': {'HR': 12, '1B': 201}, 'andeg001': {'HR': 272,...

hash['key'] to hash.key in Ruby

I have a a hash foo = {'bar'=>'baz'} I would like to call foo.bar #=> 'baz' My motivation is rewriting an activerecord query into a raw sql query (using Model#find_by_sql). This returns a hash with the SELECT clause values as keys. However, my existing code relies on object.method dot notation. I'd like to do minimal code rewrite. Th...

Can two different strings generate the same MD5 hash code?

For each of our binary assets we generate a MD5 hash. This is used to check whether a certain binary asset is already in our application. But is it possible that two different binary assets generate the same MD5 hast. So is it possible that two different strings generate the same MD5 hash? ...

Check if the user changed data

When a user registers at our site we check the address with an address validation service. This service can return an address suggestion if the entered address is found but has some errors. This sugggestion is returned to the user. The user can accept the suggestion and is trusted. If he changes the address he is not trusted. Is there ...

Should I use $_[0] or copy the argument list in Perl?

If I pass a hash to a sub: parse(\%data); Should I use a variable to $_[0] first or is it okay to keep accessing $_[0] whenever I want to get an element from the hash? clarification: sub parse { $var1 = $_[0]->{'elem1'}; $var2 = $_[0]->{'elem2'}; $var3 = $_[0]->{'elem3'}; $var4 = $_[0]->{'elem4'}; $var5 = $_[0]...