What's the difference between collision resistance and preimage resistance? [closed] - security

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
For hash function, what's the difference for collision protection and preimage protection?

from wikipedia: http://en.wikipedia.org/wiki/Cryptographic_hash_function
Properties
Most cryptographic hash functions are designed to take a string of any
length as input and produce a fixed-length hash value. A cryptographic
hash function must be able to withstand all known types of
cryptanalytic attack. As a minimum, it must have the following
properties:
Preimage resistance Given a hash h it should be difficult to find any message m such that h = hash(m). This concept is related to that of one-way
function. Functions that lack this property are vulnerable to preimage
attacks.
Second-preimage resistance Given an input m1 it should be difficult to find another input m2 — where m1 != m2 — such that hash( m1 ) = hash( m2 ). This property is
sometimes referred to as weak collision resistance, and functions that
lack this property are vulnerable to second-preimage attacks.
Collision resistance It should be difficult to find two different messages m1 and m2 such that
hash( m1 ) = hash( m2 ). Such a pair is called a cryptographic hash
collision. This property is sometimes referred to as strong collision
resistance. It requires a hash value at least twice as long as that
required for preimage-resistance, otherwise collisions may be found by
a birthday attack.

Related

Why doesn't rust allow float/int division by default? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 months ago.
Improve this question
The following snippet:
let a: f32 = 2.0;
let b: i32 = 12;
println!("{}",a/b);
fails to compile, with the error message indicating that there is "no implementation for 'f32 / i32'. Now, I understand what this error means, and that I could easily fix it by casting b before dividing. More to the point, the compiler also tells me that I could fix this without modifying the snippet above by implementing the trait Div<i32> for f32.
I don't actually need to divide ints by floats in this manner, but the compiler's message I got made me curious enough to ask the following question: why isn't Div<i32> already implemented for f32?
Of course it would be pretty easy for anyone to implement this by themselves, but I assume it must mean something that it's not a default feature. Is there some complication with the implementation I'm not thinking of? Or is it that the possibility of f32/i32 division somehow lead to "language gotcha's"? Or maybe it's just that rust is more "barebones" in this regard than I assumed?
There are multiple reasons. For one, it's not clear what the return values should be. Should 12 / 2.0 return a float or an integer? What about 12.0 / 2? Many languages opt to just return floats, but this results in hidden conversion costs. Rust as a language tries to be very explicit, especially in case of non-zero cost abstractions.
There is also type safety to consider. Sometimes doing arithmetic between ints and floats indicates a logic error.

is it possible that hash function produces the same hash value for two different inputs? [closed]

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 12 months ago.
Improve this question
is it possible that hash function produces the same hash value for two different inputs ? I am not mistaken I have read that hash function is one way encryption, so we cannot go back to the input using the result, and read that even if we change a bit of the ducoment that is directed to be hadhed will give another hash value, so how does collusion happen? and how is it possible for a hash function to produce the same value for two different inputs?
Yes. The range of any hash function is limited by the number of bits. For example, if we were to use a hash function outputting 8 bits, then we only have 256 possible outputs; so if we have more than 256 possible inputs then we are guaranteed to have a collision.
If we use a hash function with a larger range then it becomes much less likely to have a collision; but cannot make it impossible because our inputs are unlimited.
The existence of collisions is part of the reason why these functions are one way: a given output could have been generated from an unlimited number of different inputs.
We should also use a good cryptographic hash function to help avoid collisions from similar input.
You may want to look at the "SHAttered" example of 2 different PDF files that have the same SHA1 hash.

Solving Acceleration for Time with a limited velocity [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I'm working on a calculator in Excel for interstellar travel times. I'm currently solving an equation for Acceleration for Time to arrival like so:
=sqrt(distance*2/acceleration)
which seems to work fine for me, except that if I give it a large enough acceleration and long enough distance, I get a maximum velocity back that is higher than the speed of light.
What I want to do is add in some limiting factor into the formula that limits the velocity to some number, but I have no idea how to do this in the mathematics (disclaimer: I'm a writer and artist, so I suck badly at math). I think I need to integrate something like V=min(C,d/t) where C is the speed of light, but I don't know how to integrate that into my function. Since the rest of this works without having to chart out periods of time, I'd prefer a solution in the formula rather than some roundabout recursive chart trickery. Any ideas?
The right solution is of course to use the relativistic equation for the velocity after "constant acceleration" (which doesn't exist when you get near the speed of light). I suspect you mean "constant apparent acceleration" (what the passengers in the rocket feel). In that case, relativistically,
v = c * tanh(asinh(F*t/m*c))
Where
v = velocity
F = force
t = time
m = mass
c = speed of light
Then you can write F = m * a so acceleration = F / m
which you can write in Excel (after defining the constant C_ = 3E8 )
= C_ * TANH(ASINH(acceleration*time/C_)
This will initially give you linear acceleration as expected - then it will taper off and never quite reach the speed of light:
It seems to me that this equation is "the right one" for your particular application - you are not really trying to be super accurate, just have something that at least doesn't go faster than the speed of light, and transitions smoothly. In reality, what a rocket motor can do at these very high velocities, how the mass of the rocket is changing - all those things make the math a lot more complicated.
update if you want to achieve a result like the above but only have "distance" and "acceleration", we need to be a little bit tricky. Of course distance is something that depends on your frame of reference - it's different for the people in the rocket vs a stationary observer. So we are going to throw "real physics" out of the window for a minute and do something else. The straight red line in my plot represents "how fast you would be going if you kept accelerating" - this is the velocity of your initial calculation.
You can convert that to the "real" velocity with a simple
limitedVelocity = C_ * TANH(ASINH(calculatedVelocity / C_))
This is more in keeping with the question you asked, and allows you to stay in the framework you had (where you know "acceleration" and "distance" - whatever those mean in your world.)
Relativity. Blows your mind.
Afterthought
An accelerating space ship is in a non inertial frame of reference. The clock on board runs at a different speed (slower) than the "clock in the universe". Inside the spaceship the distance to their destination appears to shrink (Lorentz contraction) as they go faster. All this means that the "real" calculation depends on factors and assumptions that were not explicitly stated in the question. But since this is about an "interstellar travel calculator" by a self-professed non-physicist I think it is better not to turn this into a second year Physics of General Relativity course.
You can use an IF statement:
IF(logical_test, [value_if_true], [value_if_false])
As in:
=IF( sqrt(distance*2/acceleration) > C , C , sqrt(distance*2/acceleration) )

Understanding Travelling Salesman Time Complexity [closed]

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 have read from multiple sources and from my understanding of the algorithm that it runs in 2^N time. My question is what causes TSP to achieve this run time? I can't seem to find a pseudo-code so i can examine it.
The algorithm you mean is likely the inclusion-exclusion:
Find the shortest path though the following state space using A*:
the state is defined by the partition of the set of cities to the 'visited' set, 'unvisited' set and the 'current' node.
a valid transition is one that moves one node from 'current' to 'visited' and one from the 'unvisited' to the 'current' set. Its cost is equal the distance from the old 'current' to the new 'current'.
the starting state is: no city is 'visited', an arbitrary city is 'current'.
a finishing state is: no city is 'unvisited', any city is 'current'.
The time complexity of inclusion-exclusion is given by the number of states: there is exactly one 'current' city (factor of n) and all other cities are either visited or unvisited (factor of 2^n).
The 'A*' algorithm will enter each state at most once. For each state, it will explore at most 'n' other nodes and push them into the priority queue. The priority queue will take at most 'O(n)' time to perform its operation.
Thus, the running time is O(2^n * n * n * O(n)) = O(2^n * poly(n)). Further insight shows that O(2^n * poly(n)) is equal to O(2^n).

Haskell library like SymPy? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I need to manipulate expressions like 1 + sqrt(3) and do basic arithmetic like addition, subtraction, and division. I'd like the result to be in some sort of canonical form so that it can be used as a key in a map. Turning 1 + sqrt(3) into a float is not feasible due to roundoff problems.
I used SymPy for this task in Python. Is there an equivalent native library for Haskell?
Please check out the numbers package. If all you need is to store exact numbers like "1 + √3", you may want to use Data.Number.CReal instead of symbolic arithmetics. It stores the expressions and can be computed to arbitrary number of digits when needed.
Prelude Data.Number.CReal> let cx = 1 + sqrt (3 :: CReal)
Prelude Data.Number.CReal> showCReal 400 cx
"2.7320508075688772935274463415058723669428052538103806280558069794519330169088000370811461867572485756756261414154067030299699450949989524788116555120943736485280932319023055820679748201010846749232650153123432669033228866506722546689218379712270471316603678615880190499865373798593894676503475065760507566183481296061009476021871903250831458295239598329977898245082887144638329173472241639845878553977"
There is also a Data.Number.Symbolic module in the package but the description says "It's mainly useful for debugging".
It seems you are looking for Computer Algebra System (CAS) in Haskell. Inspite of so many references to algebraic objects in the names of Haskell packages/modules, I've never heard of a general purpose and well-maintained CA system in Haskell (like SymPy or Sage in Python).
However in the list of Computer Algebra Systems on Wikipedia I've found a reference to
DoCon. The Algebraic Domain Constructor
It uses a non-standard license, but I dare say it is still Open Source (though with rename and attribution requirements). As of July 2010 docon-2.11 still builds with GHC 6.12.1 and runs demos/tests (I only had to insert a LANGUAGE FlexibleContexts pragma in one file of the demo).
DoCon is well documented (362 pages of the Manual). Its Manual is packed inside of the zip with sources, so I put it online separately for convenience:
DoCon 2.11 Manual.ps
Please look through to check if it suits your needs.
Check out the cyclotomic package, which implements exact arithmetic on the cyclotomic numbers. These include all algebraic numbers (hence in particular 1+sqrt(3)) and the key operations (like equality) are decidable.
They do not provide an Ord instance (for the same reason the complex numbers do not), but one can implement a non-semantic instance if all one needs is to use them as keys in a lookup table. You may want to contact the author about how to do this correctly, as there may be some invariants that are not obvious (e.g. one may need to be careful about zeros in the coeffs map).

Resources