Difference between hash() and id()

There are three concepts to grasp when trying to understand id, hash and the == and is operators: identity, value and hash value. Not all objects have all three. All objects have an identity, though even this can be a little slippery in some cases. The id function returns a number corresponding to an object’s … Read more

Hash Password in C#? Bcrypt/PBKDF2

PBKDF2 You were really close actually. The link you have given shows you how you can call the Rfc2898DeriveBytes function to get PBKDF2 hash results. However, you were thrown off by the fact that the example was using the derived key for encryption purposes (the original motivation for PBKDF1 and 2 was to create “key” … Read more

Sum 2 hashes attributes with the same key

a_hash = {‘a’ => 30, ‘b’ => 14} b_hash = {‘a’ => 4, ‘b’ => 23, ‘c’ => 7} a_hash.merge(b_hash){ |k, a_value, b_value| a_value + b_value } => {“a”=>34, “b”=>37, “c”=>7} b_hash.merge(a_hash){ |k, b_value, a_value| a_value + b_value } => {“a”=>34, “b”=>37, “c”=>7}

How to convert JS Object to Array

You can do it like this (in a working snippet): var input = { “fruit” : [“mango”,”orange”], “veg” : [“carrot”] } var output = [], item; for (var type in input) { item = {}; item.type = type; item.name = input[type]; output.push(item); } // display result document.write(JSON.stringify(output)); Or, if you or someone else has been … Read more

How do methods use hash arguments in Ruby?

Example: def foo(regular, hash={}) puts “regular: #{regular}” puts “hash: #{hash}” puts “a: #{hash[:a]}” puts “b: #{hash[:b]}” end foo(“regular argument”, a: 12, :b => 13) I use hash={} to specify that the last argument is a hash, with default value of empty hash. Now, when I write: foo(“regular argument”, a: 12, :b => 13) It’s actually … Read more

Creating SHA1 Hash from NSString

I have this in a category on NSString (available at https://github.com/hypercrypt/NSString-Hashes): #import <CommonCrypto/CommonDigest.h> … – (NSString *)sha1 { NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding]; uint8_t digest[CC_SHA1_DIGEST_LENGTH]; CC_SHA1(data.bytes, (CC_LONG)data.length, digest); NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) { [output appendFormat:@”%02x”, digest[i]]; } return output; } Starting with Xcode … Read more

How can it be impossible to “decrypt” an MD5 hash? [duplicate]

Basically it’s because the output of MD5 contains less information than the input. This is basically what distinguishes a hash algorithm from an encryption algorithm. Here’s a simple example: imagine an algorithm to compute the hash of a 10-digit number. The algorithm is “return the last 2 digits.” If I take the hash of 8023798734, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)