.
#include <fstream>
#include <iostream>
#include <math.h>
#include <vector>
#include <sstream>
using namespace std;

int Next_prime(int n);
int Relativ_prime(unsigned __int64 n);
unsigned __int64 Modulo( unsigned __int64 a, unsigned __int64 b, unsigned __int64 c);
int congr(int a, int b);

int main()
{
	int choice = 0;
	cout << " 1- If you want to receive messages, type 1.\n 2- If you want to send messages, type 2.\n 3- If you have received a message, type 3.\n" << endl;
	cin >> choice;
	switch(choice)
	{
	case 1:
		{
			// CREATING A PUBLIC KEY :
	        unsigned __int64 xk, yk, nk, pk;
	        cout << " \n CREATING A PUBLIC KEY \n 1- Choose 2 big prime numbers.\n Enter a big number but less than 1000 : " << endl;
	        cin >> xk;
			int xk1 = static_cast<int>(xk);
	        xk1 = Next_prime(xk1); // find next prime of the number entered.
	        cout << " The first prime is : " <<xk1 << endl;
	        cout << " Enter a second big number also less than 1000 :\n";
	        cin.clear();
	        cin >> yk;	
			int yk1 = static_cast<int>(yk);
	        yk1 = Next_prime(yk1); // find next prime of the number entered.
	        cout << " The second prime is : " << yk1 << endl;
	        nk = xk1 * yk1;
	        cout << " The first number of the Public Key is the product of the two primes :\n";
	        cout << " It is " << xk1 << " * " << yk1 << " = " << nk << endl;
	        pk = (xk1 - 1) * (yk1 - 1);
	        cout << " 2- Now, we compute phi(n), it is phi(n) = (xk - 1) * (yk - 1), = " << pk << endl;
	        cout << " We now compute a number relatively prime to phi(n):\n";
	        int e =  Relativ_prime(pk);
	        cout << " This is the second number of the Public Key, we find : e = " << e << endl;
                cout << "\n\n Then, the Public Key is (n,e) = (" << nk << ", " << e << " )" << endl;

			// STORING THESE DATA INTO TEXT FILES
			char private_file[80];
			char public_file[80];
			cout << " Type a name for the private text file where the 2 prime numbers will be written:\n";
			cin >> private_file;
			ofstream xout1(private_file);
			xout1 << " The 2 prime numbers are :\n " << xk1 << "\n " << yk1 << "\n";
			xout1 << " The Public Key is :\n " << nk << ", " << e << endl;
			xout1.close();
			
			cout << " Type a name for the public text file where the Public Key will be written:\n";
			cin >> public_file;
			ofstream xout2(public_file);
			xout2 << " The Public Key is :\n " << nk << ", " << e << endl;
			xout2.close();

		}
	case 2:
		{

		    // SENDING A MESSAGE

		    // A - WRITING A MESSAGE AND CONVERTING IT TO NUMBERS :
		    string message;
	        cout << " Write your message, do not put any capital letters nor numbers: \n" << endl;
			cin.ignore();// or there are problems with the previous texts already entered using cin.
	        getline(cin, message);
	        int  numb, i = 0;
	        vector<int> messag;		
	        string::iterator iter;
	        for(iter = message.begin(); iter != message.end(); iter++)
	        {
		         switch(*iter)
		         {
			         case 'a':
				         numb = 11;
				         break;
			         case 'b':
				         numb = 12;
				         break;
			         case 'c':
				         numb = 13;
				         break;
			         case 'd':
				         numb = 14;
				         break;
			         case 'e':
				         numb = 15;
				         break;
			         case 'f':
				         numb = 16;
				         break;
			         case 'g':
				         numb = 17;
				         break;
			         case 'h':
				         numb = 18;
				         break;
			         case 'i':
				         numb = 19;
				         break;
			         case 'j':
				         numb = 45;
				         break;
			         case 'k':
				         numb = 21;
				         break;
			         case 'l':
				         numb = 22;
				         break;
			         case 'm':
				         numb = 23;
				         break;
			         case 'n':
				         numb = 24;
				         break;
			         case 'o':
				         numb = 25;
				         break;
			         case 'p':
				         numb = 26;
				         break;	
			          case 'q':
				         numb = 27;
				         break;
			          case 'r':
				         numb = 28;
				         break;
			          case 's':
				         numb = 29;
				         break;
			          case 't':
				         numb = 46;
				         break;
			          case 'u':
				         numb = 31;
				         break;
			          case 'v':
				         numb = 32;
				         break;
			          case 'w':
				         numb = 33;
				         break;
			          case 'x':
				         numb = 34;
				         break;
			          case 'y':
				         numb = 35;
				         break;
			          case 'z':
				         numb = 36;
				         break;
			          case ' ':
				         numb = 37;
				         break;
			          case '.':
				         numb = 38;
				         break;
			          case ',':
				          numb = 39;
				          break;
			          case ':':
				          numb = 47;
				          break;
			          case ';':
				          numb = 41;
				          break;
			          case '!':
				          numb = 42;
				          break;
			          case '?':
				          numb = 43;
				          break;
			          case '\'':
				          numb = 44;
				          break;
		            }
		            messag.push_back(numb);		
	         }
			 //for(int i = 0; i < messag.size(); i++)
				 cout << messag[i] << endl;
	         vector<int>::iterator iter1;
	         vector<int>messag1;
	         for(iter1 = messag.begin(); iter1 != messag.end(); iter1++)
	         {
		          numb = (*iter1) / 10;
		          messag1.push_back(numb);
		          numb = (*iter1) % 10;
		          messag1.push_back(numb);
	          }
			 //for(int i = 0; i < messag1.size(); i++)cout << messag1[i] << endl;
	         int bip = 0;
	         int bip1 = 1;
	         vector<int>messag2;
	         for(iter1 = messag1.begin(); iter1 != messag1.end(); iter1++)
	         {
		           if(bip==0)
		           {
			           numb = (*iter1) * 100; 
			           bip++;
			           if((*iter1==messag1.back())&&(bip1==messag1.size()))
			           {
				           numb += 36; // I add a dummy letter in the end ( 'Z' = 36 ) so that it is a 3 digits number
				           if(numb==0) numb = 036;
				           messag2.push_back(numb);
			            }
		            }
		            else if(bip==1)
		            {
			            numb += (*iter1) * 10; 
			            bip++;
			            if((*iter1==messag1.back())&&(bip1==messag1.size()))
			            {
				            numb += 3; // I add a dummy letter in the end ( 'Z' = 36 ) so that it is a 3 digits number
				            messag2.push_back(numb);
				            numb = 636;
				            messag2.push_back(numb); // for adding the 6 of the first Z and the 36 of the second Z I put 636 into messag1
			             }
		             }
		             else if(bip==2)
		             {
			             numb += (*iter1); 
			             bip = 0;
			             messag2.push_back(numb);
		              }
		              bip1++;
	         }
			 //for(int i = 0; i < messag2.size(); i++)
				 //cout << messag2[i] << endl;
			 cout << "\n ENCIPHERING THE MESSAGE \n  We compute the least residue modulo n of each number of the message\n in its numerical form to the power e. " << endl;
			 cout << "\n Enter the 2 numbers of the Public Key given to you by the receiver :\n";
			 int e1, nk1;
			 cout << "\n Enter the first number :\n";
			 cin >> nk1; 
			 cout << "\n Enter the second number :\n";
			 cin >> e1;
			 cout << endl << endl;
			 vector<unsigned __int64>messag_enciph;
	         for(int i = 0; unsigned(i) < messag2.size(); i++)
	         {
		         unsigned __int64 me = Modulo(messag2[i], e1, nk1);
		         messag_enciph.push_back(me);
	         }
			 for(int i = 0; unsigned(i) < messag2.size(); i++)
				 cout << messag_enciph[i] << endl;
	                 cout << " \n These numbers are the ciphertext that we send to the receiver. " << endl;
			 
			 // STORING THESE DATA INTO TEXT FILES
			char private_file1[80];
			char public_file1[80];
			cout << " Type a name for the private text file where\n the original text will be written:\n";
			cin >> private_file1;
			ofstream xout3(private_file1);
			xout3 << " The original text is :\n " << message << "\n " <<endl;
			xout3 << " The Enciphered message is :\n " << endl;
			for(int i = 0; unsigned(i) < messag2.size(); i++)
				 xout3 << messag_enciph[i] << endl;
			xout3.close();
			
			cout << " Type a name for the public text file where the enciphered message\n will be written:\n";
			cin >> public_file1;
			ofstream xout4(public_file1);
			//xout4 << " The Enciphered message is :\n " << endl;
			for(int i = 0; unsigned(i) < messag2.size(); i++)
				 xout4 << messag_enciph[i] << endl;
			xout4.close();
			 }
	case 3:
		{
			//RECEIVING A MESSAGE
			// 1 - CREATING A PRIVATE KEY
			cout << " \n CREATING A PRIVATE KEY \n The private key is d the solution of the congruence\n e*d congruent to 1 modulo phi(n).\n ";
			cout << "Since you receive the message you know the 2 prime numbers \n which were used to create the Public Key. Please enter them :\n" << endl;
			int aa, bb, ee, nnk;
			cout << " Enter the first prime :\n";
			cin >> aa;
			cout << " Enter the second prime :\n";
			cin >> bb;	
			cout <<" Enter the first number of the Public Key :\n";
			cin >> nnk;
			cout << " Enter the second number of the Public Key :\n";
			cin >> ee;
			int pk1 = ( aa - 1) * ( bb - 1);// this product gives us phi(n), n = product of the 2 primes.
			int dd = congr(ee, pk1);
	        cout << " d = " << dd << endl;
			cout << " \n DECIPHERING THE MESSAGE \n Write the name of the file where there is the enciphered message:\n";
			char enciph[80];
			cin >> enciph;
			ifstream xin(enciph);
			cout << " \n We compute the least residue modulo n of each number of the ciphertext\n to the power d.\n";
	        // First, we put the numbers of the ciphertext into a vector : messag_deciph
			vector<int>messag_deciph;
			char ch;
			while(xin.get(ch))
			{
				int ch1;
				switch(ch)
				{
				    case '0':
						ch1 = 0;
						break;
					case '1':
						ch1 = 1;
						break;
					case '2':
						ch1 = 2;
						break;
					case '3':
						ch1 = 3;
						break;
					case '4':
						ch1 = 4;
						break;
					case '5':
						ch1 = 5;
						break;
					case '6':
						ch1 = 6;
						break;
					case '7':
						ch1 = 7;
						break;
					case '8':
						ch1 = 8;
						break;
					case '9':
						ch1 = 9;
						break;
				    case '\n':
						ch1 = 700005;						
						break;
				}				
				messag_deciph.push_back(ch1);                
			}			
	       for(int i = 0; unsigned(i) < messag_deciph.size(); i++)cout << messag_deciph[i] << endl;
		   vector<int>messag_deciph1;// we put the digits of messag_deciph into numbers again using 700005 the carriadge return as a landmark
		   vector<int>::iterator iter4;
		   double number = 0;
		   vector<int>numb;
		   for(iter4 = messag_deciph.begin(); iter4 != messag_deciph.end(); iter4++)
		   {
			   if(*iter4!=700005)
			   {
				   numb.push_back(*iter4);
			   }
			   if(*iter4==700005)
			   {
				   int n = (numb.size()) - 1;
				   double n1 = static_cast<double>(n);
				   for(int i = 0; i < (n + 1); i++)
				   {
					   if(n1!=0)
					   {
					       number += ( ( pow(10, n1) ) * numb[i] );
					   }
					   else
					   {
						   number += numb[i];
					   }
					   n1--;
				   }
				   int number1 = static_cast<int>(number);
				   numb.clear();
				   messag_deciph1.push_back(number1);
				   number = 0;
			   }
		   }
		   for(int i = 0; unsigned(i) < messag_deciph1.size(); i++)cout << messag_deciph1[i] << endl;
		   
		   vector<unsigned __int64 >messag_deciph2;
	       for(int i = 0; unsigned(i) < messag_deciph1.size(); i++)
	       {
		       unsigned __int64 md = Modulo(messag_deciph1[i], dd, nnk);
		       messag_deciph2.push_back(md);
	       }
		   for(int i = 0; unsigned(i) < messag_deciph1.size(); i++)cout << messag_deciph2[i] << endl;
	
	       vector<unsigned __int64>::iterator iter3;
	       vector<int>messag3;
	       int xx, yy, bip3 = 0;
	       for(iter3 = messag_deciph2.begin(); iter3 != messag_deciph2.end(); bip3++, iter3++)
	       {
		       int numb = *iter3;
		       if((bip3%2)==0)
		       {
			       if(numb>=100)
			       {
				       xx = (numb) / 10;
				       yy = (numb) % 10;
			       }
			       else
			       {	
				       xx = (numb);
				       yy = 0;
			       }						
			       messag3.push_back(xx);
		       }
		       else
		       {
			       if(numb>=100)
			       {
				       xx = (numb) / 100;
				       xx += (yy * 10);
				       messag3.push_back(xx);
				       xx = (numb) % 100;
			           messag3.push_back(xx);
			       }
			       else
			       {	
				       xx = (numb) / 10;
				       xx += (yy * 10);
				       messag3.push_back(xx);
				       yy = (numb) % 10;
				       bip3++;
			       }
		       }
	       }for(int i = 0; unsigned(i) < messag3.size(); i++)cout << messag3[i] << endl;
	
	       vector<int>::iterator iter5;
	       string messag4;
	
	
	       for(iter5 = messag3.begin(); iter5 != messag3.end(); iter5++)
	       {
		       switch(*iter5)
		       {
			       case 11:
				       messag4.append(1,'a');
				       break;
			       case 12:
				       messag4.append(1,'b');
				       break;
			       case 13:
				       messag4.append(1,'c');
				       break;
			       case 14:
				       messag4.append(1,'d');
				       break;
			       case 15:
				       messag4.append(1,'e');
				       break;
			       case 16:
				       messag4.append(1,'f');
				       break;
			       case 17:
				       messag4.append(1,'g');
				       break;
			       case 18:
				       messag4.append(1,'h');
				       break;
			       case 19:
				       messag4.append(1,'i');
				       break;
			       case 45:
				       messag4.append(1,'j');
				       break;
			       case 21:
				       messag4.append(1,'k');
				       break;
			       case 22:
				       messag4.append(1,'l');
				       break;
			       case 23:
				       messag4.append(1,'m');
				       break;
			       case 24:
				       messag4.append(1,'n');
				       break;
			       case 25:
				       messag4.append(1,'o');
				       break;
			       case 26:
				       messag4.append(1,'p');
				       break;	
			       case 27:
				       messag4.append(1,'q');
				       break;
			       case 28:
				       messag4.append(1,'r');
				       break;
			       case 29:
				       messag4.append(1,'s');
				       break;
			       case 46:
				       messag4.append(1,'t');
				       break;
			       case 31:
				       messag4.append(1,'u');
				       break;
			       case 32:
				       messag4.append(1,'v');
				       break;
			       case 33:
				       messag4.append(1,'w');
				       break;
			       case 34:
				       messag4.append(1,'x');
				       break;
			       case 35:
				       messag4.append(1,'y');
				       break;
			       case 36:
				       messag4.append(1,'z');
				       break;
			       case 37:
				       messag4.append(1,' ');
				       break;
			       case 38:
				       messag4.append(1,'.');
				       break;
			       case 39:
				       messag4.append(1,',');
				       break;
			       case 47:
				       messag4.append(1,':');
				       break;
			       case 41:
				       messag4.append(1,';');
				       break;
			       case 42:
				       messag4.append(1,'!');
				       break;
			       case 43:
				       messag4.append(1,'?');
				       break;
			       case 44:
				       messag4.append(1,'\'');
				       break;
		        }
		     }
			 cout << endl <<  " The original message was :\n " <<   messag4 << endl;
		






		}
	}
	
	return 0;

}
			 

	
int Next_prime(int n)
{
	if(n==2||n==1||n==3)
		return n;
	if(n==4)
		return n + 1;


	int  r, bip = 0;
	
	while(bip==0)
	{
		double s, m;
		m = n;
		s = sqrt(m);
		int sq = static_cast<int>(s); 
		for(int d = 2; d <= sq; d++)
		{
			r = n % d; 
			if(r==0)
			{
				n++; //n is not prime
				d = sq + 1;// stops the for loop and restarts the while
			}
			if(d==sq&&r!=0) // no number between 2 and sqrt n divides n so n is prime
			{
				bip++;//stops while loop
		    } 
			else if(d==sq&&r==0)
				n++; //n is not prime
		}
	}	
	return n;
}

int Relativ_prime(unsigned __int64 n)
{

	for(int i = 2; ; i++)
	{
		int r = n % i;
		if(r!=0)
			return i;
	}

}


unsigned __int64 Modulo( unsigned __int64 a, unsigned __int64 b, unsigned __int64 c)//compute the modulo of a power b modulo c
{
    unsigned __int64 resu = 1;
	for( int i = 1; i <= b/2; i++)
	{
		   resu *= (a * a) % c; // compute a * a modulo c b/2 times
		   if((b%2!=0)&&(i==b/2))// * one time a modulo c if b is odd
			   resu *= ( a % c);
		   resu = resu % c;
	}
	
	//resu = resu % c;

	return resu;
}
		

int congr(int a, int b)// compute ax congruent to 1 modulo b, knowing that gcd(a, b) = 1;
{
	int y = a / b;
	int m = 1;
	while(m!=0)
	{
		m = ( 1 + (b * y)) % a;
		if(m!=0) y++;
	}
	int x = ( 1 + (b * y)) / a;
	while(x<0) x += b;
	return x;
	/*unsigned __int64 y = 1;
	unsigned __int64 x = ((b * y) + 1) / a;
	for(y; ;y++)
	{
		if( ((b * y) + 1) % a == 0 )
			return x;
	}*/
}


Doubly linked list (4 files)

C++ again, for finding one root of a third degree equation and checking the result , it often works fine :

For finding the 93 first Fibonacci numbers very fast , after 93 iterations it is false :

A linked list for practising :

For finding the binary representation of a number using bits :

For finding the binary representation of a number using maths :

hexadecimal representation of a number using maths :

hexadecimal representation of a number using bits :

for well understanding the structure of a linked list, here is a simple one:

It was a long and difficult linked list, but apparently, it works. Below are some other pages of code in C++, exercises most of the time. I have also put some of my plugins for 3dsmax.

I learned maxscript before learning C++, here are some scripts or plugins I did:

Next, there is some linear algebra and funny matrices:

This is now a script for enciphering and deciphering messages.

Here is an example of enciphered message. If I tell you that the 2 primes are 431 and 743 , with my script above you surely can translate the following message: 62520 172480 147764 226702 42110 58127 123996 256203 196716 181614 299597 181614 241357 187604 32762 17311 309478 29630 301116 153664 113777 14703

C++LANGUAGE
 
basicperson.h
aperson.h
aperson.cpp
ofstream.cpp
 
 
 
 
maxplugins
 
thirddegree.cpp
 
fibonacci.cpp
 
linkedlist.cpp
 
binary1
 
binary2
 
BACKHOME
 
hex1
 
hex2
 
simpleLinkedList
 
determinantmatrix
 
QRdecomposition
 
cryptography