Jump to content

Run this code as a Windows Console


Trurl

Recommended Posts

This is a program I wrote. It isn't very useful yet because I need a software library that handles large numbers. But if you read it you will see what I have been saying all along.

Of course I could be wrong, but that goes without saying. I need some computer scientist to explain how I can run a program similar to this one with large numbers.

/* This program utilizes factor patterns to estimate the value p in the N=p*q keys in RSA and other 
cryptography ciphers that use the product of semi-prime numbers.
Note it is complex to program math into a programming language. Large values could easily crash this program.
As an example I recommend testing 85 for N and 5 for x. 

Also note that finding the error between PNP and pnp_check is crucial to solving this problem. For this demenstration estimate is set
to 7. Abviously to make this program usefull estimate must be determined exactly. For now this stands as a demonstration of the equation.
*/

#include "stdafx.h"
#include <math.h>
#include <iostream>
using namespace std;

int main()
{
	bool testvalue = false;
	int PNP;
	double root, estimate = 7;
	float x, pnp_check;

	cout << "Input N the know product of 2 Prime numbers" << endl;
	cin >> PNP;


	do
	{
		cout << "Enter the small Prime factor of N as test value+." << endl;
		cin >> x;

		/*		PNPcheck = sqrt[(((((x ^ 2) * (PNP ^ 4) + 2 * PNP ^ 2 * (x ^ 5)) + x ^ 8) / PNP ^ 4) * (((PNP ^ 2) / x ^ 2)))];

		estimate = (2 * x ^ 5 / PNP ^ 2 + x ^ 8 / PNP ^ 4);
*/


		pnp_check = (((( (x*x) * (PNP*PNP*PNP*PNP) + 2 * (PNP * PNP) * (x*x*x*x*x)) + (x*x*x*x*x*x*x*x)) /   (PNP*PNP*PNP*PNP)) * ( ( (PNP*PNP) / (x*x) )));


		root = sqrt(double(pnp_check));


		if ((abs(root - double(PNP))) < ((estimate))) { testvalue = true; };


		cout << "The root that compares to N is " << root << endl;

		if (root > PNP) {
			cout << "Chose lower x if program does not end." << endl;
		};


		cout << pnp_check << endl;

		if (root < PNP) { cout << "Chose higher x if program does not end." << endl; 
		};
	
 
	} while (testvalue != true);
	
	cout << endl << endl << endl;

	cout << "The smaller Prime Factor is around  " << x << endl;
	
	
	system("pause");
	
 		return 0;
}

 

Link to comment
Share on other sites

32 minutes ago, Trurl said:

This is a program I wrote. It isn't very useful yet because I need a software library that handles large numbers. But if you read it you will see what I have been saying all along.

!

Moderator Note

All along? This is a new thread. What discussion does this support?

 
Link to comment
Share on other sites

Thanks Sensei. This program is heading for a crash with large numbers.

I believe float could handle large numbers but the Cmath library is limited in operation.

Are there any math libraries on the net with easy implementation?

I was thinking of programming it in Mathematica, but before it can be useful I have to compute the error.

Link to comment
Share on other sites

15 minutes ago, Trurl said:

Are there any math libraries on the net with easy implementation?

https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic

https://en.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software

 

12 minutes ago, Trurl said:

I believe float could handle large numbers but the Cmath library is limited in operation.

No. float is 32 bit. double is 64 bit. They are fixed.

You can read more in what range they operate on e.g. Wikipedia:

https://en.wikipedia.org/wiki/IEEE_754

 

Link to comment
Share on other sites

  • 3 months later...

Ok Sensei,

 

How do I put a very large number into this program?

 

I am not sure why a large number would cause a memory leak. I know that computers can handle many digits. But programs like Mathematica are max at x^100 power.

If I am only using the 4 arithmetic operators: addition, subtraction, multiplication, and division, why wouldn’t the computer just take more time.

Yes, I have researched it myself. I will not be using recursion to factor. That is where computers crash. But it is possible. People have factored Pi to a billion digits. I am only using a workstation. I have looked at libraries that handle large number digit operations. I believe C++ console cannot handle larger than double, because of the way it manages variables. You can’t put in a large number and expect it to go through many functions. But if I could limit it to just arithmetic operations.

 

So after reading that, my question is: How do I approach working with a 128 bit number?

 

I did not learn this in school. And it appears it is a continuing computer puzzle.

 

Oh and, Sensei and Sensei only, view my profile for the latest updates.

Link to comment
Share on other sites

Just now, Trurl said:

So after reading that, my question is: How do I approach working with a 128 bit number?

1) search net for ready linkable math libraries which allow arbitrary precision numbers.

e.g. https://en.m.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software

2) make your own C++ class. Override math operators and implement needed functionality with required higher precision.

Start from dummy class which is just using built-in double. Then add 3rd party lib functions or your own in implementation of operators.

Did you overload operators? 

8 minutes ago, Trurl said:

If I am only using the 4 arithmetic operators: addition, subtraction, multiplication, and division, why wouldn’t the computer just take more time.

After exceeding fixed precision number there is overflow.

Integer example: add 128 to 128 and it's 256. Too large to keep it in 8 bit unsigned char. In hex it is 0x100. Byte will have only the lowest bits i.e. 0x00 so you get 0 instead of 256. It is called overflow.

https://en.m.wikipedia.org/wiki/Integer_overflow

Such errors cause unpredictable behaviors of program.

Use debugger to observe values assigned to variables in the real time, and you will see it on your own eyes.

Link to comment
Share on other sites

Do you have experience linking to and using 3rd party external linkable libraries or using DLL in your C/C++ code?

Do you have experience in using debugging tools in your IDE?

Which C/C++ compiler and IDE are you using? 

Do you have experience in making subclasses of C++ class and overriding virtual methods, overloading operators etc. etc. ?

 

Link to comment
Share on other sites

I am using Visual Studio 2017.

All of my skills in C++ are just out of school and learning how to make useful programs. I have seen how to import libraries (mainly C++ libraries). I know classes, but again I have the theory of overriding but not much experience.

I am attempting to learn the Flint library. This is a library I have a book on, but I am not experienced to use it. I figured using the library is separate from understanding it, but I have found no clear-cut program that will let me plug and play large numbers.

Obviously, this isn’t very easy, or I would have found a program that will let me plug and chug my 128-bit key into a mathematical equation.

This is a learning process. I want to do this to show my math project works. I have the 128bit numbers if I could factor them it would be gold dust.

Is there no ready-made program that will do this? Cheap is important. I don’t want to spend several hundred dollars. Is there something in Linux? If something like this isn’t ready made it should be. Obviously, someone before has faced this problem. There is a worthy project here for someone with programming skills.

With limited expertise what are my options? I need to be able to complete the equation in the previous posts. It has N^6th power and then adding and diving it. So, I would take a 128-bit key and multiply it by itself 6 times creating a large monster. But it still needs only the 4 arithmetic operations of addition, subtraction, multiplication, and division. No recursion.

I also only need to test 2 to 8 values in the equation. I need one below the factor and one above the factor. It will be a math guessing game for the factor.

Link to comment
Share on other sites

In[118]:= PNP = \
1934366789178173879737044987039672886320217970368234273396727882248077\
5276979813504845595034120393370152899748537330898548017116175240963843\
8671061576515629388985879569844395850383900815310597936363427571127082\
3949399560800528445239352682682607043790064999077825592888096779406064\
2207210135237248313591984445102205903536129280729693873645010158968436\
2023257379753594951333514783850699868022479467082630988357448219611018\
0532168624955470298291740460265055263421172154319402790946210321183175\
9214437760483022798117868041446071398803987275533080729349251435281331\
126580312335348000444123257382275855627368919052416438211




x = PNP * (1/
    833333333333333333333333333333333333333333333333333333333333333333\
3333333333333333333333333333333333333333333333333333333333333333333333\
3333333333333333333333333333333333333333333333333333333333333333333333\
3)




Sqrt[((((x^2 * PNP^4 + 2* PNP^2 * x^5) + x^8) / 
     PNP^4) * ((PNP^2/ x^2)))]

Out[118]= \
1934366789178173879737044987039672886320217970368234273396727882248077\
5276979813504845595034120393370152899748537330898548017116175240963843\
8671061576515629388985879569844395850383900815310597936363427571127082\
3949399560800528445239352682682607043790064999077825592888096779406064\
2207210135237248313591984445102205903536129280729693873645010158968436\
2023257379753594951333514783850699868022479467082630988357448219611018\
0532168624955470298291740460265055263421172154319402790946210321183175\
9214437760483022798117868041446071398803987275533080729349251435281331\
126580312335348000444123257382275855627368919052416438211

Out[119]= \
1934366789178173879737044987039672886320217970368234273396727882248077\
5276979813504845595034120393370152899748537330898548017116175240963843\
8671061576515629388985879569844395850383900815310597936363427571127082\
3949399560800528445239352682682607043790064999077825592888096779406064\
2207210135237248313591984445102205903536129280729693873645010158968436\
2023257379753594951333514783850699868022479467082630988357448219611018\
0532168624955470298291740460265055263421172154319402790946210321183175\
9214437760483022798117868041446071398803987275533080729349251435281331\
126580312335348000444123257382275855627368919052416438211/\
8333333333333333333333333333333333333333333333333333333333333333333333\
3333333333333333333333333333333333333333333333333333333333333333333333\
3333333333333333333333333333333333333333333333333333333333333333333

Out[120]= \
1119462642967601379625749889949236065777407216363091843656817758630897\
2822004013012808616251428523303469194983368339224288931527755260370593\
4564726982165021366914927214391866070447793539124105460668568853618924\
3132905693874616958336079958862242579650280812660512453816275628067977\
7721150419713278365400937039926619418164741229089532498330068239309776\
1690074453198227284210005164670550843915175125291348603192500942129571\
2160296397474642360130036975254240806723286365854612676445799004846266\
7602028680911873106587947193189889293999449715734241944639662748710845\
3864217222758522411029165882690689971923777751749568939373903823332879\
0347862820497821662686301328739580127103593058742239980461079578843089\
8938404770001288892056326897984920834525603021493609403571623845097415\
9269047818150038841906826639724779147047347019045703317553593717846683\
7809250765440348545752291612966122145077943669090956833677756556314535\
3415742755622794040068289994068630691327156047081726660842339291269766\
7917971187981886248629293392246074136458310437500753586451933193176668\
2313587611783431933780044950953903564442478335965847599970260746987255\
0731160508492599759339823308128315559840203913178785278415738419343860\
320599550946803281571941063514234186096009901328/\
5787037037037037037037037037037037037037037037037037037037037037037037\
0370370370370370370370370370370370370370370370370370370370370370370370\
3703703703703703703703703703703703703703703703703703703703703703703009\
2592592592592592592592592592592592592592592592592592592592592592592592\
5925925925925925925925925925925925925925925925925925925925925925925925\
9259259259259259259259259259259259259259259259259259259259259259537037\
0370370370370370370370370370370370370370370370370370370370370370370370\
3703703703703703703703703703703703703703703703703703703703703703703703\
7037037037037037037037037037037037037037037037037037037037037

In[121]:= N[%120]

Out[121]= 1.934431447048015*10^616

Hopefully the code is readable. I need to use such operations in the guessing game. It is still trillions of digits off. But calculus can be used.

I will need help with the calculus.

I will also need advice on how to approach the programming to get large numbers into usable figures.

But I hope you agree this definitely eliminates potential values.

 

And is the large number a 1024 bit number?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.