예제 #1
0
 /*main program*/
int main ()

{
int volume, pail1, pail2, x, y, answer;
while (true){
cout << "Enter desired measurment: " ;
cin >> volume ;
cout << "Enter first pail volume: ";
cin >> pail1;
cout << "Enter second pail volume: ";
cin >> pail2;

	if ( pail1 < pail2)
   	{ x=pail1; y=pail2;}
   else
   	{x=pail2; y=pail1;}

   if ( volume > y)
   {  cout << "this volume can not be obtianed" << endl;}
   if ( coprime(x,y) == false)
   { cout << "NUMBERS ARE NOT COPRIME" << endl;break;}

pail1=0;
pail2=0;
answer=0;

	while ( answer!=volume)
 	{

   	while (pail2 < y)
      {
      pail2=pail2 + x;
      cout << "Fill " << x << " liter pail, pour into " << y << " liter pail"<< endl;
      if (pail2== volume)break;
      }

      if (pail2==volume)break;

      pail1= pail2-y;
      cout << "Empty " << y << " liter pail "<< endl;
      if (pail1==volume) break;
      cout << "Pour " << x << " liter pail into " << y << " liter pail"<< endl ;


      if (pail2==volume)break;

      answer = pail2+pail1;
      pail2= pail1;

    }
    }
}
예제 #2
0
파일: rsa.c 프로젝트: beligb/CIT595-RSA
void main() {
srand(time(NULL));
char *input = "Hello";
int *encOutput = (int *)malloc(sizeof(int) * strlen(input) + 1);
int c = 13 * 17;
int i; 
int a = 13;
int b = 17;
int e = coprime(12 * 16);
int m = totient(13 * 17);
int d = mod_inverse(e, 12 * 16); 
printf("totient = %d", totient(13 * 17));
printf("e = %d\n", coprime(12 * 16));



printf("d = %d\n", mod_inverse(coprime(12 * 16), 12 * 16));
int enc = encrypt(50, e,c);
int dec = decrypt(enc, d, c);
printf("enc = %d\n", enc);
printf("dec = %d\n", dec);


for(i = 0; i < strlen(input); i++) {
    encOutput[i] = encrypt(input[i], e, c);
     
  
}

printf("Hello has been translated into %d %d %d %d %d\n", encOutput[0], encOutput[1], encOutput[2], encOutput[3], encOutput[4]);


//    printf("coprime=%d\n",mod_inverse(3, 30));
//printf("%d", modulo(2349723,423424,12345));
//printf("mod inv = %d\n", extendedEuclid(442, 2278, &d, &x, &y));
//printf("d = %d \t x = %d \t y = %d\n", d,x,y);
//coprime(5);

}
예제 #3
0
파일: main.cpp 프로젝트: CCJY/coliru
int main() {
    unsigned wins[1001] = {};
    for (unsigned a=2; a<1000; ++a)
        for (unsigned b=a+1; b<=1000; ++b)
            ++wins[(coprime(a,b) ? a : b)];

    std::multimap<unsigned, unsigned> sorted;
    for (unsigned n=2; n<=1000; ++n)
        sorted.insert(std::make_pair(wins[n], n));

    auto iter = sorted.crbegin();
    for (unsigned i=0; i<10; ++i, ++iter)
        std::cout << iter->second << " (" << iter->first << "/999)\n";
}
예제 #4
0
void  RSA::erand(int e[MAX], int m[MAX])
{
	int i, k;
	time_t t;
	e[MAX - 1] = 5;
	do
	{
		t = time(NULL);
		srand((unsigned long)t);
		for (i = 0; i<e[MAX - 1] - 1; i++)
		{
			k = rand() % 10;
			e[i] = k;
		}
		while ((k = rand() % 10) == 0)
			k = rand() % 10;
		e[e[MAX - 1] - 1] = k;
	} while (coprime(e, m) != 1);
	return;
}
예제 #5
0
void generateKeys(long a, long b, long *e, long *d, long *c) {
    *c = a * b;
    *e = coprime( (a - 1) * (b - 1));
    *d = mod_inverse(*e,  ((a - 1) * (b - 1)));
}