Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Given two cryptographic hashes (e.g. using SHA1):
hash1 = sha1(data1)
hash2 = sha1(data2)
I would like to compose the two hashes into a value that "looks like" another hash (e.g. it is 160 bits for SHA1). Assume that only hash1 and hash2 are known, and data1 and data2 are unknown.
Option 1: compute the hash of the concatenation of the two hashes:
hash3 = sha1(concat(hash1, hash2))
Option 2: compute the XOR of the two hashes:
hash3 = hash1 XOR hash2
Which option is less likely to have collisions?
If you're concerned about hash collisions your best bet is to use a better hash algorithm, if possible (e.g. SHA-2 or SHA-3).
However, to answer your question: given two values, if you XOR them, you may see collisions even before you do the hashing. For example, 1110 XOR 1111 is 0001, and 0011 XOR 0011 is also 0001. On the other hand, concatenating the values can't introduce pre-hashing collisions. So I'd concatenate.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i need to find factors of very big number say (10^1000) . i.e if input is 100 then output should be 10 10 because (10*10=100) .this is very simple if N<=size of (long) but i want to know how it will be possible to find factors of very big number say (10^1000). also i cant use Big Integer .
.
1) As has been pointed out, factoring large numbers is hard. It is in fact sufficiently hard that it's the basis for RSA public key cryptography, or in other words every time you buy something online, you are counting on the fact that it's hard to factor numbers of the order 2^2048 (given 2^10 = 1024 which is about 10^3, 2^2048 is about 10^600). While RSA specifically uses two large prime numbers and your random N may have lots of small numbers which will help somewhat, I wouldn't count on being able to factor 10^1000 +/- some random value anytime soon.
2) You can definitely reimplement big number library using strings [source: I had a classmate who did it before we learned about how to do big number math] but it's going to be painfully slow, and you basically have to cast your strings back to ints each time; a slightly less painful approach if you wanted to reimplmeent big numbers is arrays of integers. You still need to do some extra steps, but for doing at least basic math, it's not super difficult. (But it still won't be as efficient as specialized big number libraries, which can do clever algorithms. For example, multiplying 2 big numbers the straight forward way would be let A = P * 2^32 + Q (i.e. A is a 64 bit number represented as an array of 2 32 bit numbers) and B = R * 2^32 + S... the straightforward way takes 4 multiplactions plus some additions plus some dealing with carries). As the size of the big number increases, there are ways (see e.g. http://en.wikipedia.org/wiki/Karatsuba_algorithm) to reduce the number of multipication required)
3) (There are algorithms to more efficiently factor numbers compared to trial factorization, but the current ones are still not going to help compute the numbers you're asking about before the heat death of the universe)
10^1000 has exactly 1,002,001 integer divisors, and they should be very easy to find with a bit of thinking. The prime factorisation is
2 * 2 * 2 * ... * 5 * 5 * 5
with exactly 1,000 twos and exactly 1,000 fives.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
In 1.2.1 Mathematical Induction section, Knuth presents mathematical induction as a two steps process to prove that P(n) is true for all positive integers n:
a) Give a proof that P(1) is true;
b) Give a proof that "if all P(1), P(2),..., P(n) are true, then P(n+1) is also true";
I have serious doubt about that. Indeed, I believe that point b) should be:
b) Give a proof that "if P(n) is true, then P(n+1) is also true". The major difference here is that you are only assuming that P(n) is true, not P(n-1), etc.
However, these books are old and have been read by many people (most of them being much more clever than I am^^).
So what is my confusion here?
The entire point here is that the choice of n is arbitrary. Since P(n) implies P(n+1) is the conerstone of induction, then all the intermediate values between 1 and n will also hold under the assumption of P(n). You are supposed to show that if P(0) implies P(1) and P(n) implies P(n+1) then all conditions hold by the nature of n being arbitrary.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm taking a crypto course, and we're going over substitution ciphers and their Key space.
per the instructor, the key space is 26! (approx 2^88) for the English alphabet. there is no reference to key length, probably because a subst cipher's length would be a function of the length of the alphabet, just as the number of options would.
per wikipedia the keyspace is the set of all possible keys of a certian length, and is calculated in the same way brute force try counts would be options^length or in this case 26^26.
so what am I not getting here?
That's a bit misleading, both your instructor and Wikipedia are correct.
Generally, key of 26 english letters defines a key space sized 2626.
For substitution ciphers over english alphabet 26! is the correct number representing the key space. That's because for substitution cipher the key is defined as a unique replacement of each letter with another one, e.g. A -> D, B -> M, C -> Y, etc. 26 letters --> key can be any permutation of 26-letter set --> 26!. Due to the uniqueness required for substitution, the key space is effectively smaller than the maximal 2626, because some (most) of the keys aren't possible - e.g., you can't map both A and B to D.
If your key is a set of digits, options^length is correct. Every digit may occur several times.
If your key is an alphabet, Factorial N is correct. Say, you want to place the A first. You have 26 options. After that, you have only 25 options for the B because A already occupies one. 24 For the C and so on.
26*25*24*...*1 = 26!
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Since breaking password hashes has become a new passtime for scriptkiddies, I thought of the problem and came up with a novel(?) idea.
store the pass as offset+number instead of hash
the number is a product of two large primes
the password is converted into a number , offset is added and that prime is used to divide the number. If it divides AND the divisor is the larger of the two primes the password is correct.
by definition , each hash is unique and each password can be hashed in many different ways depending on the offset. Breaking one hash means you have to factor the number(which is hard), then find a word which corresponds to a number that is largerprime-offset (which is trivial).
To generate use function f() to turn password into a password-number (not important) , generate two random primes larger than 2^4096 or however much is enough. Take the larger prime and calculate prime-passwordnumber=offset. Multiply the primes to get "number". store number and offset.
To check. use function f() to turn password into a password-number, add offset to find prime. divide number with prime to get the other prime. Check that the first prime was the bigger of the two. If so, password was correct.
f() might be for example utf-8 encoding of the password understood as a large binary integer.
Your procedure doesn't really gain you anything over using a hash function. Reversing your function is difficult, yes, since it requires factoring large numbers, but reversing regular hash functions is also difficult. An attacker can still employ the same procedure they would against a regular hash algorithm: employ a brute force attack by testing every possible password.
This, of course, is inevitable with any scheme that stores sufficient data to validate the password. The only solution is to make it computationally expensive for the attacker to do so, by making the hash function expensive to compute, and by adding a salt to make sure they can't precompute.
In general, trying to invent your own crypto system is very hard to do correctly. There are many little things that you have to consider, and it's easy to miss something that an attack can exploit. You'd still be much better off and safer if you used an established cryptography or hashing library. Bcrypt for hashing will probably be much more secure than the solution you posted.
To formalize your scheme:
To create the hash:
User enters password pw
Convert pw to a byte array ba with an encoding function e
Convert ba to a large integer bn
Find prime numbers p and q, p > q > max(bn, 2^2048)
Store n = pq and o = p - bn
To verify the hash:
User enters password pw
Convert pw to a byte array ba with an encoding function e
Convert ba to a large integer bn
Verify that bn + o divides n
This being a secure hash requires that given n and o, it's not feasible to deduce pw, i.e. there is no algorithm that gives an advantage over guessing and checking. I believe it.
As I see it, the main benefit of your scheme is the randomness injected into the hashing process by selecting the random numbers. That they are primes and factoring should be hard is more of an implementation detail (it's your one-way function). Presumably it should also slow down checks, though I really don't know how slow division is on numbers that large.
It is interesting that the hash creation and password verification processes are so different. As you point out, this makes the technique of rainbow table hash chaining inapplicable. This may be something of an advantage, but per-user salting gets you similar protection from rainbow tables.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'm not a fan of complex passwords as I have a hard time remembering them. Because of that I like the message of this comic.
However typing the sentence "correct horse battery staple" into this calculator yields "12.41 trillion trillion trillion centuries" as opposed to the comic's "550 years".
How can they differ so much, which one is correct if any and how would I know?
How do I create a strong enough password without making it difficult to remember?
The reason for this difference is basically given on the linked side itself:
IMPORTANT!!! What this calculator is NOT . . .
It is NOT a “Password Strength Meter.”
Since it could be easily confused for one, it is very important for you to understand what it is, and what it isn't:
The #1 most commonly used password is “123456”, and the 4th most common is “Password.” So any password attacker and cracker would try those two passwords immediately. Yet the Search Space Calculator above shows the time to search for those two passwords online (assuming a very fast online rate of 1,000 guesses per second) as 18.52 minutes and 17.33 centuries respectively! If “123456” is the first password that's guessed, that wouldn't take 18.52 minutes. And no password cracker would wait 17.33 centuries before checking to see whether “Password” is the magic phrase.
The caclulator basically only considers brute force attempts, while an actual attack would probably be a dictionary arrack. Since most combinations of letters are not actual words a dictionary attack will try a lot less combinations, thous getting a result much faster
IMPORTANT!!! What this calculator is NOT . . .
It is NOT a “Password Strength Meter.”
The calculator assumes that cracker uses exhaustive search. xkcd assumes that cracker may know (or guess) your method of generating password and needs to check only the passwords which you can choose. xkcd method is far safer.
Not any strong password is 100% safe, few websites can really protect user's password. You'd better not to use only one password everywhere. What you do is to keep the straw on fire away from others.
What I do is:
a unforgettable password: A;
the website asking for a password, "www.example.com", as B;
get C = md5(A) + md5(B), and use the leading 8 characters of C as the password;
write a simple script for this, and of course, you may adjust the algorithm, and do keep the script on cloud.
the browser will save password for us, if it asks you for re-enter the password, you can get it back at once.
The operator '+' is not as strcat. It means:
I get the md5 in low letters, and saying that the '0' values 0, ..., 'a' values 10, ..., 'A' is 36, ..., and as so on.Then calculate the result at every character with their values, discarding the carry, and do "mod(62)".