Say I am hashing hashes (taking the hash of a previous hash) for an endless amount of time.  How many times would it take, on average, to fall into a loop when using SHA-2 (more specifically SHA-256 and SHA-512), like such:  original text = z (can be any string) hash z = b hash b = c hash c = d  ...  hash n = b (restarting loop)   or more literally,  original text = "test" SHA-256 of "test" = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" SHA-256 of "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" = "7b3d979ca8330a94fa7e9e1b466d8b99e0bcdea1ec90596c0dcc8d7ef6b4300c"  ...  SHA-256 of n = SHA-256 of "test" = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"   How many attempts, on average, would this take?
104858
Let's say I start with a particular 256 bit value. Call this $v$. I then hash that value, and get another 256 bit value. Call this $\text{SHA256}(v)$. I take this value and get another 256 bit value. Call this $\text{SHA256}^2(v)$. More generally, let's call the result of hashing $v$ repeatedly $n$ times $\text{SHA256}^n(v)$.  Now my question is, how big will $n$ be, such that $\text{SHA256}^n(v) = v$?  It would seem to me, that if it's a giant sort of permutation, $n$ would have to be $2^{256}$, is that correct? Is that provable, or is there any information on this? (Just curiosity, really.)  Another question I had was, do all 256 bit strings have unique SHA256 values, and is there a way to show that? (Or, stated differently, can it be shown that there are no SHA-256 collisions in the language of all "256 bit strings"?)
82865
I am going through some of my notes from class (About Information Security) and I'm stuck understanding how my teacher got this result. The question is:     How many collisions would you expect to find in the following cases?      a) Your hash function generates a 12-bit output and you hash 1024 randomly selected messages.      b) Your hash function generates an n-bit output and you hash m randomly selected messages.    The teacher's only answered a) like so:         We expect to find one collision every $2^{n/2}$ hashes. There are $2^{(n/2) * 2} = 2^n$ comparisons. Since the output is 12-bit the answer is $2^{10 * 2}/2 ^{12} = 2^{8} = 256$ collisions.   However I don't quite understand how he got this?  I get that the expected number of collision after n hashes would be $2^{n/2}$. But the rest doesn't make sense to me. I mean if the output is 12 bits (4096 arrangements), why would we expect to get 256 collision after only hashing 1024 messages (1/4 of the possible outputs)?
4243
I want to find the md5 hash of the string "a", but running echo "a" | md5sum gives me another hash than what I get if I search the internet (for example using  or ).  Running echo "a" | md5sum gives me "60b725f10c9c85c70d97880dfe8191b3", but it should be "0cc175b9c0f1b6a831c399e269772661".  If I make a reverse hash lookup for "60b725f10c9c85c70d97880dfe8191b3", I do however get "a".
93203
How many bit strings containing exactly eight $0$s and twelve $1$s have either all the $0$s consecutive, or all the $1$s consecutive?  My working :  There are $20$ positions $(8 + 12)$   Since there are $2$ possibilities for each position   Thus $2^{20}$
29728
In other words, can I do something like  for() {     for {        for {        }     } }   Except N times? In other words, when the method creating the loops is called, it is given some parameter N, and the method would then create N of these loops nested one in another?  Of course, the idea is that there should be an "easy" or "the usual" way of doing it. I already have an idea for a very complicated one.
35188
I didn't get the answer to this anywhere. What is the runtime complexity of a Regex match and substitution?  Edit: I work in python. But would like to know in general about most popular languages/tools (java, perl, sed).
62492
I was wondering if there's any string that has a hash equal to itself, so that – when using any (none specific) hash function – the hash would be equal to that string?  so that:  hash(x) = x   Note that this is not an assignment or anything. I’m just curious and couldn't find any specific answer or reference. And I’m not sure how to go and prove/disprove that to myself!
617
I understand how for hash functions which are vulnerable to length extension attacks (such as SHA1 and SHA2) it is safer to use a HMAC construction.  What I don't understand is, how or why is $\operatorname{HMAC\_SHA256}_\mathrm{key}(\mathrm{message})$ safer (in terms of resistant against certain attacks) than $\operatorname{SHA256}(\mathrm{key}_1 \mathbin\| \mathrm{message} \mathbin\| \mathrm{key}_2)$, assuming that all key strings are sufficient in length and entropy?
50003
Bad hash functions are not so perfect as in the ""  hypothesis... And a general concept of "collision resistence"  not need the constraint  of independence between the hash function and the sample set.  Let $H$ be a hash function with digest of $k$ bits, and $S$ a input sample set with size $s=|S|$.$H$ is collision resistant if it is "hard to find" two inputs that hash to the same output, &nbsp; $\exists x\ne y\in S|H(x)=H(y)$  But "hard to find" is not a good definition: to compare the performance of two hash functions $H_1$ and $H_2$ we need a precise metric... Wikipedia  use $Pr[H]$, the ... But, in real-life tests or benchmarking, we have only the number of collisions $c$, and a big standard deviation to compare $c$ values when change $S$ or $H$.  Puting the question in other words:  &nbsp; there are a "standard way" to obtain the real-life $Pr[H]$ of bad hash functions?    Context. Let me be a programmer that buy low quality proprietary software that implement exotic hash functions: the hash function $H$ for me is a , and I need to test it.    So, if the seller of the function says it is resistant, I need to check it by experiments and some statistical analysis of the experimental results.    Back to the question... If this standard exists, I am supposing that is a kind of probability definition, so,  will be someting like (is it? need only to check the number $c$ of collisions) $$Pr[H](S)=\frac{c}{|S|}=\frac{c}{s}$$  Bad hash functions () have characteristic values of $Pr$ that not depends only on $|S|$...  We can use  $c$ to compare the efficiency of the bad hash  with other hashes. I am imagining that  I can  use $c$ or an averaged $\overline{c}$ based on many $c_i$ tests as a metric of collision rates.    NOTES  Let $c_1$ the number of collisions in $H_1(S)$ and  $c_2$ the number of collisions in $H_2(S)$, them we can compare the two hash functions.  To avoid bias we can do an average about many sample sets $S_1$, $S_2$, etc. So there are averaged $\overline{c}_1$ and  $\overline{c}_2$ as good estimators.   we can also estimate the minimum $\overline{c}$ of a hash function with digests of $k$ bits by   $${Pr}_{min}[H](S) ~=~  1 - \frac{2^k!}{(2^k)^s (2^k - s)!} ~\approx~ 1 - exp({-s^2/2^{k + 1}})$$  Conclusion, a good score to compare hash functions is $$q ~=~ Pr[H](S) - Pr_{min}[H](S) ~\approx~ \frac{\overline{c}}{s} -1+exp({-s^2/2^{k + 1}})$$  When $q=0$ we have "perfect hash function", that have an expected behaviour about collisions... Imagining that hashes like SHA1 are always perfect because is impossible to compute $\overline{c}$, but  truncated SHA1 or "bad hashes" can be tested about big $S$ samples. PS: negative $q$ is possible when  $H$ and $S$ are not independent.   My interest is the behaviour of these truncated or bad hashes, and to compare them.
81455
Suppose I have a set of elements, with known hash (e.g. SHA-2). How can I calculate the hash of the set? With it I mean an unordered set, so the order of elements is undefined and shall not play any role in determining the hash of the set.  In theory any commutative operation applied to the hashes should be fine, but I have the strong feeling that XORing all of them together is quite unsafe. An attacker could add an element to the set to produce a hash collision, although finding an element with that wanted hash is as hard as breaking the hash of the whole set.  Anything better solution than the trivial one of sorting the elements into a list, calculating their hashes and then calculating the hash of the hash list?  I think Merkle trees can't help here if they are based on some sort of ordering of the elements.
96085
Regarding the cryptosystem known as the Hill Cipher,  has an exercise asking you to find the number of involutory keys for $m=2$ over $\mathbb Z_{26}$. This means that we are to find the number of $2\times 2$ matrices over $\mathbb Z_{26}$ that satisfies $K=K^{-1}$. This can be considered a basic mathematical problem regardless of the details of the Hill Cipher cryptosystem.    I have found the number to be $736$ by applying the easily proven result $$ K=K^{-1}\implies\det(K)=\pm1\pmod{26} $$ stated in the previous exercise, and the general formula $$ \begin{pmatrix} a&amp;b\\c&amp;d \end{pmatrix}^{-1} =\det(K)^{-1} \begin{pmatrix} d&amp;-b\\-c&amp;a \end{pmatrix} $$ stated elsewhere in the textbook and hinted at in the exercise in question.    But here is my problem:     This approach seemed far from general, dividing into cases and subcases regarding whether $\det(K)=1$ or $\det(K)=-1$ and regarding the profiles of $a,b,c$ modulo $2,13$ respectively (Chineese Remainder Theorem [CRT]). This lead to conclusions equivalent to saying that for $\det(K)=-1$ the equation $K=K^{-1}$ has $4$ solutions over $\mathbb Z_2$ and $182$ solutions over $\mathbb Z_{13}$. By [CRT] this provides $4\cdot182=728$ solutions over $\mathbb Z_{26}$ for the subcase $\det(K)=-1$. The case $\det(K)=1$ provided $8$ matrices in my analysis.   So my question is:     Is there a general approach for finding the number of solutions to the matrix equation $K=K^{-1}$ over a prime field $\mathbb Z_p$ for matrices of arbitrary size $m\times m$?
28212
There are many examples of MD5 collisions (some of them can be found here ). But as far as I know two inputs should have the same length to have the same MD5 (or same hash in general). Is it correct? Is there any proof of that?  Or otherwise examples of inputs of different lengths with the same MD5?
24120
I'm currently trying to introduce myself to cryptography.  I'm reading about the Hill Cipher currently in the book Applied Abstract Algebra. The Hill Cipher uses an invertible matrix $M$ for encryption and the inverse matrix $M^{-1}$ for decryption. The book recommends to use a matrix $M$ for which it holds that $M=M^{-1}$, since we then have the same key for encryption and decryption.  In the book, they use a $2 \times 2$ matrix $M$ over $\mathbb{Z}_{26}$ as example, and state that for there are 736 $2 \times 2$ matrices for which it hold that $M=M^{-1}$.  I'm trying to pick up on as much as possible when reading things, since I find it counter-productive for learning to skip something, when you don't get the theory behind it. Can someone enlighten to me, as to why it is that there are 736 possible $2 \times 2$ $M=M^{-1}$ matrices and how to find them?
39353
To be clear, I have access to $H(S)$ and as many $H(S||K)$ as I want. Every string $K$ is known. Can I use the extra information to my advantage and try to deduce $S$, without requiring bruteforce? Or do you still have to bruteforce but try less combinations since you have more information?
71410
I'm wondering if anyone can shed light on a worry of mine that a query_plan_hash collision could cause a query to be executed as an entirely different query.  The hash is a 16 digit Hex that sp_help sys.dm_exec_query_stats says is a binary. Therefore it's only a 64 bit hash, and a collision seems very probable (considering SHA1 [160 bit] was just verified to have had collisions).  Would the plan_hash and the query_plan_hash both have to collide for this (query to be executed as an entirely different query) to happen?  I'm also curious if there is a setting somewhere in SQL Server that will allow us to change this hash to SHA2-512 (to reduce the possibility of a collision). Our data is very important.  I searched high and low via Google and Stack Exchange forums.
81625
Is hashing a password twice before storage any more or less secure than just hashing it once?  What I'm talking about is doing this:  $hashed_password = hash(hash($plaintext_password));   instead of just this:  $hashed_password = hash($plaintext_password);   If it is less secure, can you provide a good explanation (or a link to one)?  Also, does the hash function used make a difference?  Does it make any difference if you mix md5 and sha1 (for example) instead of repeating the same hash function?  Note 1:  When I say "double hashing" I'm talking about hashing a password twice in an attempt to make it more obscured.  I'm not talking about the .  Note 2:  I know I need to add a random salt to really make it secure.  The question is whether hashing twice with the same algorithm helps or hurts the hash.
41227
A lot of times in Perl, I'll do something like this:  $myhash{foo}{bar}{baz} = 1   How would I translate this to Python? So far I have:  if not 'foo' in myhash:     myhash['foo'] = {} if not 'bar' in myhash['foo']:     myhash['foo']['bar'] = {} myhash['foo']['bar']['baz'] = 1   Is there a better way?