Lehmann Test for prime numbers [closed] - cryptography

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 learn cryptography at my university, and I need to make an application for testing numbers as prime numbers.
I must to do it using Lehmann Test, but I don't know anything about it. Please, describe me the algorithm or give me an example (Java, C#, C++, etc). Thank you for helping.

Let's call PP your Potential Prime.
(1) Choose a random number a less than PP.
(2) Calculate a^(p-1)/2 mod PP.
(3) If a^(PP-1)/2 /= 1 or -1 (mod PP), then PP is not prime.
(4) If a^(PP-1)/2 = 1 or -1 (mod PP), then the probability that PP is not prime is less than 50%.

Related

How to make correct function in dynamic programming [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 4 years ago.
Improve this question
I have the following problem in dynamic programming.
A person has time machine and he can move in time either 1 year or 2. At the beginning he is at year 0 and he wants to reach year 100. Every step he does (1 or 2 years) he is paying some fixed fees. There is an array with 100 integers represents the fee he needs to pay if he went threw the specific year.
I need to find the minimum amount the person can pay to go from year 0 to year 100 using dynamic programming.
From what i have done so far i think that there should be something like
minCost(i) = min{A[i-1], A[i-2]}
and the base cases are years 1 and 2 which costs A[1], A[2] respectively. But i think this approach has more of greedy algorithm rather than dynamic programming.
I saw the bin packing algorithm of dynamic programming and i understood it and the matrix that represents it.
How should the matrix of the shown problem above look like?
And how should i build the function and the pseudo code for this problem?
You are almost there.
Think about how will you reach the i th year from i-1 th year and i-2 th year. There is a fee which you are forgetting to take into consideration.
MinCostToReachYear(i) = min( MinCostToReachYear(i-1) + fee(i-1), MinCostToReachYear(i-2) + fee(i-2) )
You already know the base cases year 1 and year 2. Can you think of extrapolating with the use of a for loop or more easily with a recursive function which you already know as mentioned above? I leave it as an exercise for you.

how to find factors of very big number [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
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.

What are typical lengths of chat message and comment in database? [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 8 years ago.
Improve this question
I need to create a column in SQL Server database. Entries for that column will contain messages from chat. Previously such messages has been stored as comments.
My main quetion is:
What is typical text length for chat message and comment?
By the way:
What would happen if I used varchar(max)? How would it impact database size and performance? Is better to use powers of 2 or powers of 10 (e.g. 128 instead of 100) while considering text lengths?
Using VARCHAR(MAX) has a disadvantage: you can not define an index over this column.
Generally, your application should impose a maximum length for a chat message. How big that limit is depends very much on what the application is used for. But anything more than 1000 byte is probably less a legitimate message but an attempt to disrupt your service.
If your maximum value is a power of 2, or a power of ten or any other value has no influence on the performance as long as the row fits in one (8KB) page.
Short answer - it doesn't matter.
From MSDN:
The storage size is the actual length of the data entered + 2 bytes.
So VARCHAR(10) and VARCHAR(10000) will consume the same amount of data if the values don't exceed 10 characters.
Definitely use N/VARCHAR(MAX), it can grow to be 2GB (if I remember correctly). It will grow as required though, so it is very efficient with regards to space unless you are only storing very small amounts of data.

This is very easy but i am struck with one [closed]

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 9 years ago.
Improve this question
This is findind limit calculus one. This would be very easy but i never factor high degrees. can anyone show me how to factor it.
lim((x^5-32)/(x-2),x=2)
lim((x^5-2^5)/(x-2),x=2)
As John suggested in the comments above: when x-->2 we handle a limit of type 0/0. In order to calculate it we use the derivative of the numerator and a derivative of the denominator:
f'(X^5-2^5) = 5x^4
---------- ----
f'(x-2) = 1
if we'll substitute x with 2 we'll get:
5*2^4
----- = 80
1

The Art of Computer Programming (2nd ed.): Mathematical Induction [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 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.