hash

Hashing pointers as Keys for unordered_map in C++ STL

一曲冷凌霜 提交于 2020-01-01 09:23:40
问题 I posted a similar quetion regarding using pointers as Keys on maps in C++ STL. How are pointers hashed in unordered_maps when used as Keys. More specifically if I define: std::unordered_map< CustomClass*, int > foo; Would the default C++ std::hash implementation work to handle these pointers? Is it safe to use? Is this good practice? 回答1: std::hash<T*> is defined but the details of how it operates are implementation dependent. It will certainly be safe to use, and I'd consider it good

Data structure for efficiently returning the top-K entries of a hash table (map, dictionary)

家住魔仙堡 提交于 2020-01-01 09:23:08
问题 Here's a description: It operates like a regular map with get , put , and remove methods, but has a getTopKEntries(int k) method to get the top-K elements, sorted by the key: For my specific use case, I'm adding, removing, and adjusting a lot of values in the structure, but at any one time there's approximately 500-1000 elements; I want to return the entries for the top 10 keys efficiently. I call the put and remove methods many times. I call the getTopKEntries method. I call the put and

How can I store a hash in a SQL Server database using C#?

拟墨画扇 提交于 2020-01-01 09:21:11
问题 I'm trying to make a website with a log on / log off feature and I plan on properly hashing and salting the password. The problem I'm facing, however, is how I'd go about storing the password in the database. I know that I need to store the hashed + salted password in the database (not in plain text or plain encrypted), but I don't know how to technically get around inserting the binary data into the database. In my early attempts, the only way I could get the data in the database would be to

How can I store a hash in a SQL Server database using C#?

一笑奈何 提交于 2020-01-01 09:20:06
问题 I'm trying to make a website with a log on / log off feature and I plan on properly hashing and salting the password. The problem I'm facing, however, is how I'd go about storing the password in the database. I know that I need to store the hashed + salted password in the database (not in plain text or plain encrypted), but I don't know how to technically get around inserting the binary data into the database. In my early attempts, the only way I could get the data in the database would be to

what is has_zero and find_zero in word_at_a_time.h used for

只愿长相守 提交于 2020-01-01 09:15:49
问题 In linux kernel, inlucde/linux/word_at_a_time.h, there are two functions: static inline long find_zero(unsigned long mask) { long byte = 0; #ifdef CONFIG_64BIT if (mask >> 32) mask >>= 32; else byte = 4; #endif if (mask >> 16) mask >>= 16; else byte += 2; return (mask >> 8) ? byte : byte + 1; } static inline bool has_zero(unsigned long val, unsigned long *data, const struct word_at_a_time *c) { unsigned long rhs = val | c->low_bits; *data = rhs; return (val + c->high_bits) & ~rhs; } It's used

Bcrypt for password hashing because it is slow?

我只是一个虾纸丫 提交于 2020-01-01 09:07:14
问题 I read today on not-implemented.com : Sha-256 should be chosen in most cases where a high speed hash function is desired. It is considered secure with no known theoretical vulnerabilities and it has a reasonable digest size of 32 bytes. For things like hashing user password, though, a function designed to be slow is preferred: a great one is bcrypt. Can somebody explain the last sentence : For things like hashing user password, though, a function designed to be slow is preferred: a great one

SHA256 in PHP & Java

流过昼夜 提交于 2020-01-01 07:08:08
问题 I'm porting some Java code to PHP code. In Java I have a hash SHA256 code as below: public static String hashSHA256(String input) throws NoSuchAlgorithmException { MessageDigest mDigest = MessageDigest.getInstance("SHA-256"); byte[] shaByteArr = mDigest.digest(input.getBytes(Charset.forName("UTF-8"))); StringBuilder hexStrBuilder = new StringBuilder(); for (int i = 0; i < shaByteArr.length; i++) { hexStrBuilder.append(Integer.toHexString(0xFF & shaByteArr[i])); } return hexStrBuilder.toString

Ruby: Converting a nested Ruby hash to an un-nested one

久未见 提交于 2020-01-01 05:40:09
问题 Right now, I have a server call kicking back the following Ruby hash: { "id"=>"-ct", "factualId"=>"", "outOfBusiness"=>false, "publishedAt"=>"2012-03-09 11:02:01", "general"=>{ "name"=>"A Cote", "timeZone"=>"EST", "desc"=>"À Côté is a small-plates restaurant in Oakland's charming Rockridge district. Cozy tables surround large communal tables in both the main dining room and on the sunny patio to create a festive atmosphere. Small plates reflecting the best of seasonal Mediterranean cuisine

Produce MD5 or SHA1 hash code to long (64 bits)

情到浓时终转凉″ 提交于 2020-01-01 05:26:06
问题 I need to compute a hash code of a string and store it into a 'long' variable. MD5 and SHA1 produce hash codes which are longer than 64 bits (MD5 - 128 bits, SHA1 - 160 bit). Ideas any one? Cheers, Doron 回答1: You can truncate the hash and use just the first 64 bits. The hash will be somewhat less strong, but the first 64 bits are still extremely likely to be unique. For most uses of a hash this is both a common and perfectly acceptable practice. You can also store the complete hash in two 64

How do I use SHA-512 with Rfc2898DeriveBytes in my salt & hash code?

那年仲夏 提交于 2020-01-01 05:04:08
问题 I'm completely new to cryptography, but learning. I've pieced together many different suggestions from my research online, and have made my own class for handling the hash, salt, key stretching, and comparison/conversion of associated data. After researching the built-in .NET library for cryptography, I discovered that what I have is still only SHA-1. But I'm coming to the conclusion that it's not bad since I'm using multiple iterations of the hash process. Is that correct? But if I wanted to