23

I'm confused by the phrase “one way hash value” and so is probably whoever specified this requirement. In cryptography, a one-way hash function has a well-defined meaning. Let \$\Sigma\$ be an alphabet, for example, \$\Sigma=\{\mathtt{0}, \mathtt{1}\}\$. A family of functions \$(f_k)_{k\in\mathbb{N}}\$ with $$f_k: \Sigma^k \times \Sigma^* \to \Sigma^k$$ ...


17

There are some issues with this function, some of them resulting from the fact that the task to be performed was poorly conceived to begin with. The statement of the problem says that Ascii takes a "one character string". You give it a character, not a one-character string. Note that the Ascii function is completely unnecessary: a character in the ASCII ...


13

There are some basic issues here, as well as some algorithmic complexities, and then some advanced suggestions. Basic issues relate to Java code conventions, etc. Basics Use try-with-resources. You have code which may fail, and leave open files lying around to be garbage collected. Consider the following code: try (FileInputStream fi1 = new ...


13

I can see no advantage of computing the hash value from Int(self.x) and Int(self.y). As you already noticed, truncating the floating point numbers to integers loses information and therefore causes hash collisions. CGFloat is (like all Swift number point types) Hashable, and its hashValue is just the integer with the same memory representation (as one can ...


13

I think you are missing the point. Different objects can produce same hashcode. This can happen: obj.Equals(otherObj) // false obj.GetHashCode() == otherObj.GetHashCode() //true If for some reason you want your Equals methods to return true when hashcodes are equal, then by all means. Make sure to document this behavior though. However if you want to ...


11

I'm not particularly familiar with C, but I have a few observations that may be helpful. I like the attention to zeroing out your digest before you start. Using uninitialised memory is the sort of bug that can go unnoticed for a while, and it's good that you've caught it. At the same time, I'm slightly alarmed that you're doing everything with raw loops, ...


10

Reinventing the wheel Please note that encryption should, in principle, always be two way. A 'one way encryption' just sounds weird. Normally something is encrypted with the intention to decrypt it at a later stage. This is not what you do. What you do is called hashing or perhaps 'encoding' as you indicated in your title. You could improve the formatting ...


10

Why build your own implementation when you can use the features available in the Java standard libraries? IdentityHashMap gives you all the features you need, and a Java Stream/collector will allow you to extract the map easily from your collection.... Collection<Test> tests = ..... Map<Test,Test> uniques = tests.stream().collect(Collectors....


10

We really need to start by defining the kind of hash function we've created - this doesn't appear to be a useful cryptographic (one-way) hash function, yet creating strings as output seems to be a poor choice for hashes used for performance purposes (as keys in unordered maps and sets, for example). What is the intended problem domain here? We have a very ...


9

First impressions The code seems very clean and tidy. As far as I can tell, you're including exactly the required headers - no more, and no less. There's generally good use of const and static, but left_rotate() could benefit from constexpr, and digest() and hex_digest should both be const. Separability Consider moving the member function definitions ...


8

I do not understand why val was introduced in addition to value – it isn't even a copy of the contents. On the other hand h does make sense once you consider thread safety. Assume we have two threads which calculate the hash of the string at nearly the same time – to trigger this, have both threads sleep for a moment when they enter the if branch. At the ...


8

It ignores values in superclasses. You might want to check that too. Anyway, don't reinvent the weel, there is a library for that! I guess EqualsBuilder.reflectionEquals from Apache Commons Lang does exactly what you want. It also has solutions to corner cases, like transient fields (since they are likely derived fields, and not part of the value of the ...


8

Nice implementation. Good attention to shift types. Use bool. Various members, functions are used only in a boolean fashion. Use bool to add clarity to that use. Yet I suppose this goes against "ANSI C with as little specific C99 as possible". // int single_one_delivered; // int total_len_delivered; // int calc_chunk(uint8_t chunk[CHUNK_SIZE], struct ...


7

You should check if the references are equal first to save a whole lot of comparing when there is no need to. If both objects are null your method will return false which is probably unexpected. You call getClass() several times on these objects - It should only be called once for each object and then stored in a local variable. There is a typo in ...


7

Some general comments about the code: /* The 16 fractional parts of the cuberoots of the first 64 prime numbers. */ const __uint64 fractional_cubehash[16]{ Is perhaps the comment / array name misleading? The fractional_cuberoots[64] array supposedly contains the fractional parts of the cuberoots of the first 64 prime numbers, and fractional_cubehash[16] ...


7

No, it isnt. First, you only allow ASCII characters in the password. If I were to choose €¥≠≥≤©® as my password, it would probably be equivalent to choosing ??????? (7 question marks). Try it. Second, a password hashing function must be slow. Otherwise it is too easy to crack the password. Third, when you hash a password, you must add some salt to it. ...


6

As KIKO Software and the documentation for crypt said, password_hash() is encouraged. It's safer (it applies multiple rounds of hashing, thus increasing the time it takes to decrypt the hash), and it will manage salts for you, which means that your code will be simpler. If for some reason you do not want to use password_hash, note the warning from the ...


6

The name of the function crypt() is somewhat misleading, but you're not encrypting and decrypting. You create a hash and you check it, that's it. It's not the best I have seen, but it is not uncommon to do it this way. In the PHP crypt() documentation it says: Use of password_hash() is encouraged. You didn't see that? It allows you to choose an algorihtm....


6

Both your methods should work. As far as I know, there is no alignment problem on the current OS X and iOS architectures in your first method (see below). The code from the second method can be simplified a tiny bit: - (uint64_t)digestFromString: (NSString *)s { NSData *input = [s dataUsingEncoding: NSUTF8StringEncoding]; union { // uint64_t-...


6

Just a couple of points which are more from a stylistic point-of-view rather than strict language requirements or algorithmic correctness: Classes should be named upper-case: Car, House, TwoTimesPlusOne, Addition Interfaces should also be named upper-case: InfixOperator Variable names should use camel-case: leafIndex, unsignedValue i, j and k are used as ...


6

The Hashable protocol has only one single requirement: Axiom: x == y implies x.hashValue == y.hashValue. So let's start with your implementation of ==: // Hashable also needs struct to conform to Equatable protocol func ==(left: ScalarString, right: ScalarString) -> Bool { if left.length != right.length { return false } for var ...


6

Structure Okay, let's start with the basic overall structure of the function: it's, frankly, not very good. It (unnecessarily) depends on a number of outside variables--from its perspective, essentially globals. There's no good reason that this couldn't be a nice, pure function--i.e., take an input parameter, do the hash, return a result. No reference to ...


6

It looks alright to me, although it seems odd having a young man of age 20 to equal an "elderly" man of age 30 :-). I have 3 minor things: 1) One MemoryStream can be used to serialize all expressions: public Func<T, byte[]> Build(Func<byte[], byte[]> computeHash) { return obj => { var binaryFormatter = new BinaryFormatter()...


6

Please be careful with the indentation because it looks like there are different number of spaces for different indentation depths and it looks very weird. Minor improvements: Repetition md5 = hashlib.md5() path = same_size[size][i] md5 = hashlib.md5() I am almost sure there is no reason to repeat md5 = hashlib.md5() twice. "Native" iteration while ...


6

I know this isn't really what you're asking for, but I have a couple suggestions about how the code is setup and written. Coming from languages that use long as a type, a line like: self.storedURLS[tiny] = long Is a little jarring initially. No, long is not a type or builtin in Python, but I think it would be neater if a more descriptive name was used, ...


5

You can replace new Date().getTime() by System.currentTimeMillis() For the rest of the code, it would help if you explain the algorithm you are implementing, or if you name it (if it's a known hash algorithm)


5

The hashCode method can be simplified down to (just simply restructuring your logic and removing redundancy): @Override public int hashCode() { return id == null ? 0 : id.hashCode(); } The equals method is a bit more complicated. Your code does appear to keep the hashCode/equals contract, so that is good, but, sometimes there are better ways than ...


5

Your code does seem open to some improvement. Right now, you're not really getting much good out of using a pointer to a function. You could just about as well invoke each hash function directly in findLowHash as call it via a pointer in foundLow. In this case, we have a number of functions that all have the same signature, so we can create an array of the ...


5

First of all, you can improve on reading the command-line arguments and, instead of manually parsing the sys.argv, use argparse module. Something like: import argparse def parse_args(): """Parses command-line arguments.""" parser = argparse.ArgumentParser() parser.add_argument('infile', type=argparse.FileType('r')) parser.add_argument('...


5

If you're going to write a lot of Hash classes, then you'll want to simplify the creation of the class. Take for example HashcatHash, the following is much simpler to create, than what you're doing: class HashcatHash(Hash): _regex = "(.*?)::::([0-9a-f]{48}):([0-9a-f]{16})" _format = "{d[username]}::::{d[response]}:{d[challenge]}" def parse(m): ...


Only top voted, non community-wiki answers of a minimum length are eligible