How to add new item to hash
Create the hash: hash = {:item1 => 1} Add a new item to it: hash[:item2] = 2
Create the hash: hash = {:item1 => 1} Add a new item to it: hash[:item2] = 2
Using sorted(d.items()) isn’t enough to get us a stable repr. Some of the values in d could be dictionaries too, and their keys will still come out in an arbitrary order. As long as all the keys are strings, I prefer to use: json.dumps(d, sort_keys=True) That said, if the hashes need to be stable across … Read more
Picking atoms on 10 Moons An SHA-1 hash is a 40 hex character string… that’s 4 bits per character times 40… 160 bits. Now we know 10 bits is approximately 1000 (1024 to be exact) meaning that there are 1 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 … Read more
fcn time generated hash crc32: 0.03163 798740135 md5: 0.0731 0dbab6d0c841278d33be207f14eeab8b sha1: 0.07331 417a9e5c9ac7c52e32727cfd25da99eca9339a80 xor: 0.65218 119 xor2: 0.29301 134217728 add: 0.57841 1105 And the code used to generate this is: $loops = 100000; $str = “ana are mere”; echo “<pre>”; $tss = microtime(true); for($i=0; $i<$loops; $i++){ $x = crc32($str); } $tse = microtime(true); echo “\ncrc32: … Read more
hash.each do |key, array| puts “#{key}—–” puts array end Regarding order I should add, that in 1.8 the items will be iterated in random order (well, actually in an order defined by Fixnum’s hashing function), while in 1.9 it will be iterated in the order of the literal.
It should suffice to say whether bcrypt or SHA-512 (in the context of an appropriate algorithm like PBKDF2) is good enough. And the answer is yes, either algorithm is secure enough that a breach will occur through an implementation flaw, not cryptanalysis. If you insist on knowing which is “better”, SHA-512 has had in-depth reviews … Read more
Documentation for crypto: http://nodejs.org/api/crypto.html const crypto = require(‘crypto’) const text=”I love cupcakes” const key = ‘abcdeg’ crypto.createHmac(‘sha1’, key) .update(text) .digest(‘hex’)
hash[:new_key] = hash.delete :old_key
Summary: It’s not a coincidence; _PyHASH_INF is hardcoded as 314159 in the default CPython implementation of Python, and was picked as an arbitrary value (obviously from the digits of π) by Tim Peters in 2000. The value of hash(float(‘inf’)) is one of the system-dependent parameters of the built-in hash function for numeric types, and is … Read more
A public salt will not make dictionary attacks harder when cracking a single password. As you’ve pointed out, the attacker has access to both the hashed password and the salt, so when running the dictionary attack, she can simply use the known salt when attempting to crack the password. A public salt does two things: … Read more