Plaintext(binary) : 10101100 //very short for easy understanding

Suppose we have 4 predefined schemes/functions,

  1. rotate (101 -> 011)
  2. flip (1101 -> 1011)
  3. exchange (11011 -> 10111)
  4. stretch (1100 -> 11001100)

We create a function that checks for '0' or '1' in each position of plaintext(binary)

function in simple terms, (suppose plaintext in binary 10101100)

  1. Bit at position 1 is 1, so perform rotate() on plaintext.
  2. Bit at position 2 is 0, don't perform flip() operation.
  3. Bit at position 3 is 1, so perform exchange() on output of step 1.
  4. Bit at position 4 is 0, don't perform stretch operation.
  5. Bit at position 5 is 1, so perform rotate() on output of step 3.
  6. Bit at position 6 is 1, so perform flip() on output of step 5.
  7. Bit at position 7 is 0, don't perform exchange().
  8. Bit at position 8 is 0, don't perform stretch().

In this the output would be dependent on the input, hence it may serve as a hash to the plaintext. These functions are just for example, more complex functions may be used. I've used just 4 functions however more functions can be used.

I don't know if this is already the logic in existing hashing schemes but had this thought in mind. Will this work as a proper hashing scheme? (I suppose no)

  • 2
    $\begingroup$ This seems like a case of rolling your own crypto. What are you trying to achieve? $\endgroup$
    – domen
    Dec 17, 2014 at 16:55
  • 2
    $\begingroup$ One of the characteristics of a cryptographic hash is that it transforms a variable-length message into a fixed-length digest. Your proposed algorithm fails on that count. Other important characteristics are that the algorithm must be non-invertible and collision-resistant. Unless you are qualified to make those analyses, you aren't qualified to develop cryptographic algorithms. I tell students that they need a Ph.D. in math and ten years' experience with crypto before they start rolling their own. $\endgroup$
    – Bob Brown
    Dec 17, 2014 at 17:12
  • $\begingroup$ @BobBrown You can also sign that for migration. If 4 of 5 people signed for migration to the same site, it got migrated automatically. But signing something to migrate requires 3 clicks and we are lazy - and the SE wants to make this hard too. $\endgroup$
    – peterh
    Dec 17, 2014 at 17:59
  • $\begingroup$ @BobBrown I don't think things were so dark, practically a looped permutation/exchange with randomly selected parameters is in most cases enough. $\endgroup$
    – peterh
    Dec 17, 2014 at 18:05
  • $\begingroup$ you should have a look here: crypto.stackexchange.com/a/17925/17650 $\endgroup$ Feb 19, 2015 at 10:11

2 Answers 2


I don't recommend inventing your own hashing algorithm unless if you are knowledgeable and careful. The available hashing functions are good SHA 3 was chosen based on an open competition, you may just use it.

I don't see a point of coming up with a new hash function.

  • 4
    $\begingroup$ This probably should have been a comment. $\endgroup$
    – mikeazo
    Jan 20, 2015 at 13:37

I don't think it were a good hash, although I think it is reparable.


The first thing which we can find on the spot, as @BobBrown said: hash functions create a fixed-length result from a variable-length input. Your function does exactly the opposite.

A possible fix: you segment the output and simply XOR the segments together.


Both of rotate and flip are special cases of permutation, maybe you had to go in this direction?


Simply execute these functions isn't enough! The power of the hash (and similar crypto) functions happen only if you execute the permutation / substitution loops many (at least 16-32) times! And so isn't always impossible that somebody maybe find a crack. You had especially watch the possibility of the birthday attack, although after 10 years of postdoc crypto research you will have probably much better ideas to crack a such algorithm, too.


Your hash based on turning on/off different transformations. Thus, some of your hashes won't even execute a single (or at most 2) of your trafos. In these cases, your hash will be very easily crackable (probably even by pure eye).

A possible fix: change your algorithm, instead of turning on/off the trafos, turn them always in, but mix their parameters.


In your case I forgot the scretch, executed your algorihtm many times, and used a xor-based (or much complexer) overlapping, to provide the fixed output size.


If your hash is ready, use a lot of analysis! Check for:

  • distributions of randomly created hashes are enough "equal" (randomly)
  • changing a single bit in the input should change mean half the bits in the output, and the changed bits should distribute also randomly.

These are trivial things, on crypto SE you could get much better tips too.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy