Answered # How to ask input if input is not a prime number

rch1231 169 zeroliken 79 Discussion Starter logicslab Schol-R-LEA 1,003 Discussion Starter logicslab Schol-R-LEA 1,003 Discussion Starter logicslab Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...

0

Hello,

Your going to have to test to see if the number is in a list of the prime numbers. They are fixed after all and you can find out what they are in multiple places on the internet.

For example here is a site that has the first 1000 primes:

0

lots of code snippets can be found on the net to check if a given input is prime, here's a few from a quick search

http://holmezideas.com/programming/optimization-techniques/fastest-algorithm-to-check-if-a-given-number-is-prime/

http://www.programmingsimplified.com/c/source-code/c-program-for-prime-number

*Edited 3 Years Ago by zeroliken*

0

Dear friends,

I am not looking the logic of prime number , i need to ask the system to enter prime number upto i give that .... I admit it include checking of prime with repeated input entry .... please help with a solution

Thanks,

anes

0

Could you please clarify what it is you need for us? It sounds as if you are having difficulty with the input itself. Is that correct?

Assuming that this is the case, then there are a few options you can choose. The simplest of these is to use `scanf()`

to read in the number, and checking the return value to make sure that it did in fact read in integer (`scanf()`

returns the number of characters read, which in this case would be the number of actual digits read in).

However, using `scanf()`

directly has its disadvantages; for one, it leaves behind whatever extra characters were in the data stream, such as the newline, which you then have to manually clear. I would recommend instead that you read the data in using `fgets()`

, and then using `sscanf()`

(note the extra 's') to extract the integer from the read line of data.

```
int possible_prime, retval;
char buffer[MAX_LINE]; // whatever you set MAX_LINE to be
// ... now we skip to where you're reading in the data...
do
{
printf("Enter a number to test for primality: ");
fgets(buffer, MAX_LINE, stdin);
retval = sscanf(buffer, "%d", &possible_prime); // note the ampersand - we use a pointer to the variable here
} while (retval == 0);
```

*Edited 3 Years Ago by Schol-R-LEA*

0

Dear pals,

I create thread on bytes forum , regarding this issue . Please look this thread : Click Here

and help me to implement the RSA algorithm in C. I got the concept of fgets() and sscanf() already . issue in the implementation of primality test for that .please advise

Thanks,

Anes

0

OK, that does explain things a little, but it still isn't clear what you really need. It sounds as if you are looking to test whether a given public key's numerical value is prime; but that makes no sense - the whole point of the encryption algorithm is that it uses values too large to be factored in a reasonable time period given current hardware. That's why you select 'pseudo-primes' (numbers very likely to be prime, but which can't be factored quickly) rather than ensuring the primality for the keys.

0

DEAR @SCHOL,

IN RSA ALGORITHM IT(e - public key) MUST BE USE PRIME NUMBER WHICH IS NOT THE CONFACTOR OF 'PHI'

Here we input (or randomly insert) two prime numbers p and q

n = p*q
phi = (p-1)*(q-1)

e = must be a prime number - which we chcek now in this thread - but not cofactor of phi

eg : if we give p = 11 & q = 3

then phi = 10*2 = 20

so we cannot give 5 for e , because it's cofactor of 'phi'(ie 20).

So the value e is a subset of PRIME Numbers .

We need to find the 'd' - Private key from formula

d*e mod phi = 1

Then if M is the Message to encrypt( Here M is integer value in range : 0<M<n)

C- Cipher text , which generate from M

C = M^e mod n[Encryption]

and

M = C^d mod n [Decryption]

This is the criteria(Condition) for RSA algorithm

Dear @vegas,

I am looking your 'Miller-Robin primality test'

Thnks,

Anes

This question has already been answered. Start a new discussion instead.

Recommended Articles

Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.

btn_addline :

`Private Sub btn_addline_Click(ByVal ...`

I don’t want at this stage work on a big separate project as I've already got plenty ...