Java: Composite key in hashmaps

You could have a custom object containing the two strings: class StringKey { private String str1; private String str2; } Problem is, you need to determine the equality test and the hash code for two such objects. Equality could be the match on both strings and the hashcode could be the hashcode of the concatenated … Read more

Compute a hash from a stream of unknown length in C#

MD5, like other hash functions, does not require two passes. To start: HashAlgorithm hasher = ..; hasher.Initialize(); As each block of data arrives: byte[] buffer = ..; int bytesReceived = ..; hasher.TransformBlock(buffer, 0, bytesReceived, null, 0); To finish and retrieve the hash: hasher.TransformFinalBlock(new byte[0], 0, 0); byte[] hash = hasher.Hash; This pattern works for any … Read more

Uniform distribution of truncated md5?

Yes, not exhibiting any bias is a design requirement for a cryptographic hash. MD5 is broken from a cryptographic point of view however the distribution of the results was never in question. If you still need to be convinced, it’s not a huge undertaking to hash a bunch of files, truncate the output and use … Read more

error for hash function of pair of ints

Unfortunately, this program has undefined behavior. C++11 ยง17.6.4.2.1: A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited. hash<pair<int,int>> depends on primitive and standard … Read more

How do I convert a Ruby hash to XML?

ActiveSupport adds a to_xml method to Hash, so you can get pretty close to what you are looking for with this: sudo gem install activesupport require “active_support/core_ext” my_hash = { :first_name => ‘Joe’, :last_name => ‘Blow’, :email => ‘joe@example.com’} my_hash.to_xml(:root => ‘customer’) And end up with: <?xml version=”1.0″ encoding=”UTF-8″?> <customer> <last-name>Blow</last-name> <first-name>Joe</first-name> <email>joe@example.com</email> </customer> Note … Read more

CommonHMAC in Swift

You can do it in Swift. Just make sure you add #import <CommonCrypto/CommonHMAC.h> to the bridging Objective-C bridging header. Update: For Swift 4 see a much better solution using the Swift Package Manager here: https://github.com/jernejstrasner/SwiftCrypto enum CryptoAlgorithm { case MD5, SHA1, SHA224, SHA256, SHA384, SHA512 var HMACAlgorithm: CCHmacAlgorithm { var result: Int = 0 switch … Read more

Why is it not possible to reverse a cryptographic hash?

MD5 is designed to be cryptographically irreversible. In this case, the most important property is that it is computationally unfeasible to find the reverse of a hash, but it is easy to find the hash of any data. For example, let’s think about just operating on numbers (binary files after all, could be interpreted as … Read more

How Do Hardware Token Devices work? [closed]

This has very little to do with hash functions. A cryptographic hash function may be part of the implementation, but it’s not required. Actually, it generates the digits on a time-based interval, if I press the button for it to generate the digits, it generates the digits and after about 25 seconds, and I press … Read more

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