Hash functions violating some pre image properties [closed] - hash

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 6 years ago.
Improve this question
Suppose H(xy) = H(x) * H(y) . Clearly preimage properties are violated. How can we find x, y such that H(x) = H(y) mod (2^k)

2^k is a very special modulus. You can prove the following strengthened version of Euler's theorem:
Suppose that x is any postive integer. Then x^phi(2^k) (mod 2^k) is equal to either 0 or 1, with 1 if and only if x is odd.
Proof:
If x is odd, then gcd(x,2^k) = 1, hence x^phi(2^k) (mod 2^k) = 1 by Euler's theorem.
Suppose that x is even. The result is trivially true if x = 0, so suppose that x > 0. Write x = (2^s)*y where y is odd and s > 0. Note that
phi(2^k)` = 2^(k-1)
But then,
x^phi(2^k) = (2^s*y)^phi(2^k)
= (2^s)^phi(2^k) * y^phi(2^k)
= 2^(s*phi(2^k)) * y^phi(2^k)
= 2^(s*2^(k-1)) * y^phi(2^k)
= 0 * y^phi(2^k) = 0 (mod 2^k)
the last line follows from the fact that s*2^(k-1) >= k hence 2^(s*2^(k-1)) is a multiple of 2^k.
Note that if x is even then you actually have x^k = 0 (mod 2^k), so raising x to the power phi(2^k) is overkill for any but the smallest k.
Given this lemma, it is now trivial to see that there exists distinct x,y with either H(x) = H(y) = 0 or H(x) = H(y) = 1. Since it seems to be homework, I'll leave the details to you.

Related

Filter coefficients in matlab [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm learning about signal processing and currently I have to do an speech synthesizer in Matlab. For emulate the resonator system of the mouth I've this transfer function:
R(z) = 1 - z ^(-1)
Can I implement this system with filter function in Matlab? I don't know how to extract the coeficients "a" and "b"...
Note: y = filter(b, a, x), where x is the input signal that we have to filter.
Thank you all!
Consulting the documentation for filter, you represent a transfer function as a rational function of coefficients such that:
The desired transfer function you want, Y(z) / X(z) = R(z) is equal to:
R(z) = 1 - z^{-1}
Here a(1) is implicitly equal to 1. Therefore, b(1) = 1 and b(2) = -1 referring to the above equation. All of the coefficients in the denominator are 0 except for a(1) which is equal to 1.
As such, a = 1; b = [1 -1]; and so filtering your signal is simply:
a = 1; b = [1 -1];
y = filter(b, a, x);
x is the signal of interest you want to filter.

Transform imperative algorithm into formula (or prove they produce the same output) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I saw someone write the code below:
var row = 0
var incr = true
var numRows = 5
for idx in 0..<10 {
print(row)
if row == 0 {
incr = true
} else if row == numRows - 1 {
incr = false
}
row = (incr) ? row+1 : row-1
}
The code's goal is to make the variable "row" increase and decrease like:
row = 0 1 2 3 4 3 2 1 0 1 2 3 4 2 1 ...
But the author improves his code and the result likes below
var numRows = 5
let L = numRows - 1
for idx in 0..<10 {
row = L - abs(L - idx % (2*L))
}
I know the result of "row" is the same, but I don't know how to transfer version 1 to version 2. How do I prove that it's the same?
Developing a formula like that requires an understanding of and familiarity with the modulo and absolute values operators. These are things that you develop over time if you play with math problems and read programs. Once you get the hang of them, you can figure out other formulas that give the same result, such as abs((i + L) % (2 * L) - L).
Anyway, given the formula in your question, try to convince yourself that it does what the first program does by building up the formula one step at a time and graphing the steps.
Computing i % (2*L) for 0 ≤ i < ∞ gives a repeating cycle of the integers from 0 to 2*L (including 0 but excluding 2*L):
Computing L - i % (2*L) turns that into a repeating cycle of the integers from L down to -L (including L but excluding -L):
Taking the absolute value of that sequence (abs(L - i % (2*L))) changes the negative part of the sequence to positive, so you get a repeating cycle of first the integers from L down to 0, then back up to L (including the first L and 0 but not the second L, so you don't get two L's in a row):
Subtracting that sequence from L (L - abs(L - i % (2*L))) flips L to 0, L-1 to 1, etc., and 0 to L. So you get a repeating cycle from 0 to L and back to 0 (including 0 and L but not repeating 0 twice in a row):
This is the same sequence produced by the first program.

How to get solution to make this determinant zero? [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 7 years ago.
Improve this question
A = [A-x(1) B-x(2) C-x(3);D-x(4) E-x(5) F-x(6); G-x(7) H-x(8) I-x(9)]
I have to obtain x(1)...x(9) for det(A) = 0.
Given a 3x3 matrix A
its determinant is
therefore you need to solve |A| = 0. For your case we are given
The easiest solution for x so that |A| = 0 is when
a - x(1) = 0
b - x(2) = 0
c - x(3) = 0
which leads to
x(1) = a
x(2) = b
x(3) = c
so
x = A
is the most trivial solution. There exists an infinite number of solutions to this problem, this is just one. You could choose another solution where
a - x(1) != 0
b - x(2) != 0
c - x(3) != 0
and then you would have to set
ei - fh = 0
di - fg = 0
dh - eg = 0
which would involve simultaneous equations.
I suggest before trying to code up a solution you work through one by hand like I've done here.

Interpolating arrays with different vectors [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have multiple arrays that I need to identify and interpolate to a set number. the set number will be the 'length?' of the biggest array. I need to How could I identify each array length and create a loop to interpolate each array to that specific length? Sorry if I am not providing enough detail.
A = rand(10,2);
B = rand(20,2);
C = rand(5,2);
%find max length, for you cell array you want: max(cellfun(#(x) length(x), MyCellArray))
n = max([length(A), length(B), length(C));
%repeat for each, i.e. loop through the cell array
x = A(:,1);
y = A(:,2);
m = min(x);
M = max(x);
d = (M - m) / n;
xi = m:d:M;
Ai = interp1(x, y, xi);

how get the index of the minimum element of each row of matrix in MATLAB [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am attempting to write a code to find index of the minimum element of each row from the 'distance' matrix, excluding zeroes from the matrix.
If the distance matrix is a (large) sparse matrix, this problem is somewhat more nontrivial. The best approach is probably to subtract the (max value * 2) from each nonzero element in each row. This seems ugly and hackish but I can't think of any other efficient way to solve it.
sub = max(0, max(myArray,[],2) * 2);
[i,j,v] = find(myArray);
v -= sub;
myArray = sparse(i,j,v);
[junk mi] = min(myArray,[],2);
EDIT: There are still precision issues if elements within a row have very different magnitudes. If this is the case, you can take negative inverses instead. In this way, you're not combining magnitudes from different elements in the matrix (or with any constant)
posOnly = ~any(myArray < 0, 2);
[i,j,v] = find(myArray);
inds = posOnly(i);
v(inds) = -1 ./ v(inds);
myArray = sparse(i,j,v);
[junk mi] = min(myArray,[],2);
(Note the use of ~any(myArray < 0) rather than all(myArray >= 0) because (myArray < 0) is at least as sparse as myArray whereas (myArray >= 0) is not sparse)
Using Dan's hint:
myArray(myArray==0)=Inf;
[m mi] = min(myArray, [], 2);
The values of mi will be the index of the minimum element in each row. Note the minimum is taken along the second dimension (per dspyz's suggestion).