Posts: 42
Threads: 7
Joined: Oct 2009
Reputation:
4
(10-09-2009, 06:34 AM)Headshot Wrote: So, now that they did this thing.. what does it do?
It's not completely done yet.
It could get the RSA password in couple billion years.
Posts: 345
Threads: 30
Joined: Oct 2009
Reputation:
7
(10-09-2009, 06:41 AM)L0iz Wrote: It's not completely done yet.
It could get the RSA password in couple billion years. COUPLE BILLION YEARS?
Posts: 116
Threads: 10
Joined: Oct 2009
Reputation:
4
10-09-2009, 07:03 AM
(This post was last modified: 10-09-2009, 07:16 AM by Etheryte.)
Another rebuild, to make it more compact.
Code: //Include standard input-output.
#include <stdio.h>
//Function to check, whether the provided number is a prime, if it is, returns 0.
int start(int a)
{
int i;
for(i=2;i<(a/2)+1;i++)
{
if(a%i==0)
return 1;
}
return 0;
}
//My lovely main function.
int main()
{
//Lets the user know the program is online.
printf("Starting...\n");
//Declare variables
int l,i,n,d,a;
//Ask for a number.
printf("Please enter your number: ");
scanf("%d",&d);
//Negativity check.
if(d<0)
{
printf("The number you provided is negative and can't be achieved via multiplus of two positive numbers.\n");
getchar();
getchar();
return 0;
}
i=2;
n=0;
//Find out how many primes there are from 0 to the number provided
while(i<d/2)
{
if(start(i)==0)
{
n++;
i++;
} else {
i++;
}
}
//How many primes you need to find the number provided.
l=n;
//An array large enough, to hold the primes.
int primes[l];
//The first prime is 2, ergo i=2 at kickoff.
i=2;
n=0;
//While the array is not filled with primes...
while(n<=l)
{
//Find primes. If i is a prime, stick it in the array.
if(start(i)==0)
{primes[n]=i;
n++;
i++;}
else
//If it isn't, keep searching.
{i++;}
}
//Notify of the results, how many primes were calculated, etc.
printf("Done calculating the first %d primes into an array.\n",(l+1));
printf("The last calulated prime is %d.\n",primes[l]);
printf("Searching now...\n");
//Check if the provided number can be produced by multiplying numbers from the array, which holds the primes.
for(a=0;a<n;a++)
{
for(i=0;i<n;i++)
if(primes[a]*primes[i]==d)
{
//If yes, print out the numbers.
printf("Gotcha, your primes are %d and %d!",primes[a],primes[i]);
getchar();
getchar();
return 0;
}
}
//Check, if the provided number is a prime on itself, if it's not achievable by multiplying other primes.
if(start(d)==0)
{
printf("Provided number is a prime on itself and is not achiavable via multiplus of other primes.\n");
getchar();
getchar();
return 0;
}
//If not, be sad. =(
printf("No primes identified.");
getchar();
getchar();
return 0;
}
//Written by Etheryte, released to the free world.
Posts: 42
Threads: 7
Joined: Oct 2009
Reputation:
4
(10-09-2009, 06:56 AM)Headshot Wrote: COUPLE BILLION YEARS?
Yep, RSA can't be decrypted today, but it might be done with The Quantum Computer.
This script actually has no practical use.
Posts: 116
Threads: 10
Joined: Oct 2009
Reputation:
4
10-09-2009, 07:09 AM
(This post was last modified: 10-09-2009, 07:16 AM by Etheryte.)
Also, sorry for spamming your Python thread with C.
Final code:
Code: //Include standard input-output.
#include <stdio.h>
//Function to check, whether the provided number is a prime, if it is, returns 0.
int start(int a)
{
int i;
for(i=2;i<(a/2)+1;i++)
{
if(a%i==0)
return 1;
}
return 0;
}
//My lovely main function.
int main()
{
//Lets the user know the program is online.
printf("Starting...\n");
//Declare variables
int l,i,n,d,a;
//Ask for a number.
printf("Please enter your number: ");
scanf("%d",&d);
//Negativity check.
if(d<0)
{
printf("The number you provided is negative and can't be achieved via multiplus of two positive numbers.\n");
getchar();
getchar();
return 0;
}
//Check, if the provided number is a prime on itself, if it's not achievable by multiplying other primes.
if(start(d)==0)
{
printf("Provided number is a prime on itself and is not achiavable via multiplus of other primes.\n");
getchar();
getchar();
return 0;
}
//Check, if the provided number can be divided by 10.
if(d%10==0&&d!=10)
{
printf("No primes identified. (Number divides by 10.)");
getchar();
getchar();
return 0;
}
i=2;
n=0;
//Find out how many primes there are from 0 to the number provided
while(i<d/2)
{
if(start(i)==0)
{
n++;
i++;
} else {
i++;
}
}
//How many primes you need to find the number provided.
l=n;
//An array large enough, to hold the primes.
int primes[l];
//The first prime is 2, ergo i=2 at kickoff.
i=2;
n=0;
//While the array is not filled with primes...
while(n<=l)
{
//Find primes. If i is a prime, stick it in the array.
if(start(i)==0)
{primes[n]=i;
n++;
i++;}
else
//If it isn't, keep searching.
{i++;}
}
//Notify of the results, how many primes were calculated, etc.
printf("Done calculating the first %d primes into an array.\n",(l+1));
printf("The last calulated prime is %d.\n",primes[l]);
printf("Searching now...\n");
//Check if the provided number can be produced by multiplying numbers from the array, which holds the primes.
for(a=0;a<n;a++)
{
for(i=0;i<n;i++)
if(primes[a]*primes[i]==d)
{
//If yes, print out the numbers.
printf("Gotcha, your primes are %d and %d!",primes[a],primes[i]);
getchar();
getchar();
return 0;
}
}
//If not, be sad. =(
printf("No primes identified. (Via calculations.)");
getchar();
getchar();
return 0;
}
//Written by Etheryte, released to the free world.
Download in exe form.
Posts: 42
Threads: 7
Joined: Oct 2009
Reputation:
4
It's OK.
It might actually help someone.
Also I now see your "biggest number" point, my script can deal with any number, but if it's not valid (e.g. not a factor of 2 primes) it will just keep running.
Posts: 116
Threads: 10
Joined: Oct 2009
Reputation:
4
10-09-2009, 08:49 AM
(This post was last modified: 10-09-2009, 08:57 AM by Etheryte.)
My script should virtually manage any number, as long as you have the time and the computer has the power. It also stops, if the number can't be a factor of two primes.
You can just review my code if you want an easy solution to the running problem.
Posts: 42
Threads: 7
Joined: Oct 2009
Reputation:
4
(10-09-2009, 08:49 AM)Etheryte Wrote: My script should virtually manage any number, as long as you have the time and the computer has the power. It also stops, if the number can't be a factor of two primes.
You can just review my code if you want an easy solution to the running problem.
When writing my script I was also thinking about the array.
But eventually I decided that one prime is calculated, then tested and again.
I think I'll also make an array version.
Sorry for offtopic anyways.
Posts: 116
Threads: 10
Joined: Oct 2009
Reputation:
4
I think that an array version would be faster, then it generates the numbers at first, after that it's easier calculus.
Posts: 103
Threads: 7
Joined: Oct 2009
Reputation:
5
And yes I'm aware that was only an "isprime" function, just trying to help some others out lol
Terrorcore, unleash, extermination
Hyper real, cold blood, determination
fudge them, I like this sensation
Incredible, I from the annihilation
|