RSA Algorithm

import java.io.*;
import java.util.*;
import java.math.*;
class RSA
{
public static void main(String args[]) throws IOException
{
Double p,q,n,d,c,t,m;
Double e=13.0;
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Two Prime Numbers:");
p=Double.parseDouble(br.readLine());
q=Double.parseDouble(br.readLine());
n=p*q;
t=(p-1)*(q-1);
d=Math.pow(e,-1);
d=((1+k*t)/e);
System.out.println("enter the message");
m=Double.parseDouble(br.readLine());
c=Math.pow(m,e)%n;
t=Math.pow(c,d)%n;
System.out.println("Encrypted message"+c);
System.out.println("original message"+m);

}
}
Output:

C Programs.

1.Prime Numbers programs using C

#include<stdio.h>
 
main()
{
   int n, i = 3, count, c;
 
   printf("Enter the number of prime numbers required\n");
   scanf("%d",&n);
 
   if ( n >= 1 )
   {
      printf("First %d prime numbers are :\n",n);
      printf("2\n");
   }
 
   for ( count = 2 ; count <= n ;  )
   {
      for ( c = 2 ; c <= i - 1 ; c++ )
      {
         if ( i%c == 0 )
            break;
      }
      if ( c == i )
      {
         printf("%d\n",i);
         count++;
      }
      i++;
   }         
 
   return 0;
}

2.Print Diamond Pattern using C

#include <stdio.h>
 
int main()
{
  int n, c, k, space = 1;
 
  printf("Enter number of rows\n");
  scanf("%d", &n);
 
  space = n - 1;
 
  for (k = 1; k <= n; k++)
  {
    for (c = 1; c <= space; c++)
      printf(" ");
 
    space--;
 
    for (c = 1; c <= 2*k-1; c++)
      printf("*");
 
    printf("\n");
  }
 
  space = 1;
 
  for (k = 1; k <= n - 1; k++)
  {
    for (c = 1; c <= space; c++)
      printf(" ");
 
    space++;
 
    for (c = 1 ; c <= 2*(n-k)-1; c++)
      printf("*");
 
    printf("\n");
  }
 
  return 0;
}

3.Print Pascal Tringle using C

#include<stdio.h> long factorial(int); main() { int i, n, c; printf("Enter the number of rows you wish to see in pascal triangle\n"); scanf("%d",&n); for ( i = 0 ; i < n ; i++ ) { for ( c = 0 ; c <= ( n - i - 2 ) ; c++ ) printf(" "); for( c = 0 ; c <= i ; c++ ) printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c))); printf("\n"); } return 0; } long factorial(int n) { int c; long result = 1; for( c = 1 ; c <= n ; c++ ) result = result*c; return ( result ); }
Output:
1 1 1 1 2 1 1 3 3 1

4.Palindrome Program using C

#include<stdio.h> main() { int n, reverse = 0, temp; printf("Enter a number to check if it is a palindrome or not\n"); scanf("%d",&n); temp = n; while( temp != 0 ) { reverse = reverse * 10; reverse = reverse + temp%10; temp = temp/10; } if ( n == reverse ) printf("%d is a palindrome number.\n", n); else printf("%d is not a palindrome number.\n", n); return 0; }

Method Overloading

import java.util.*;
import java.io.*;
class Overloading
{
 
 void Test()
 {
  System.out.println("No. Parameters::");
 }
 void Test(int a)
 {
  System.out.println("a:"+a); 
 }
 void Test(int a,int b)
 {
  System.out.println("a and b:"+a+" "+b);
 }
 double Test(double a)
 {
  System.out.println("double a::"+a);
  return a*a;
 }
 

 
}
class Overload
{
 public static void main(String args[])
 {
  Overloading o1=new Overloading();
  double result;
  o1.Test();
  o1.Test(10);
  o1.Test(10,20);
  result=o1.Test(123.25);
  System.out.println("result:::"+result);
 }
}
Output:

Addition of Two Matrix.

import java.util.Scanner;
class AddTwoMatrix
{
public static void main(String args[])
{
int m, n, c, d;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n  = in.nextInt();
int first[][] = new int[m][n];
int second[][] = new int[m][n];
int sum[][] = new int[m][n];
System.out.println("Enter the elements of first matrix");
for (  c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
first[c][d] = in.nextInt();
System.out.println("Enter the elements of second matrix");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
second[c][d] = in.nextInt();
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
sum[c][d] = first[c][d] + second[c][d];  //replace '+' with '-' to subtract matrices
System.out.println("Sum of entered matrices:-");
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
System.out.print(sum[c][d]+"\t");
System.out.println();
}
}
}


output:


/*2D Rotation program in computer graphics in c with output*/


2D Rotation Algorithm
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>


void rotate( int figure[], int edges, double angle, int cx, int cy )
{
      double x, y;
      angle = -1 * (angle*3.14/180);
      double cos_a = cos(angle);
      double sin_a = sin(angle);

      for(int i=0; i < edges; i++)
      {
            x = figure[2*i] - cx;
            y = figure[2*i+1] - cy;
            figure[2*i] = ceil( (* cos_a) - (* sin_a) + cx );
            figure[2*i+1] = ceil( (* sin_a)+(* cos_a) + cy );
      }
}

void main()
{
      int figure[20], edges;  // A Figure with Max 10 edges.
      double angle;
      int cx=0, cy=0;
      int gd = DETECT, gm;
      initgraph( &gd, &gm, "" );
      int max_y = getmaxy();
      clrscr();
      cleardevice();

      printf( "Number of edges: " );
      scanf( "%d", &edges );

      for(int i=0; i < edges; i++)
      {
            printf( "Enter edge (x%d,y%d) : ", i , i );
            scanf( "%d %d", &figure[2*i], &figure[2*i+1] );
      }
      figure[2*i] = figure[0];
      figure[2*i+1] = figure[1];
      edges += 1;

      printf( "Enter angle of rotation in degrees: ");
      scanf( "%lf", &angle);

      printf( "Enter the center of rotation: \n");
      printf( "cx: ");
      scanf( "%d", &cx);
      printf( "cy: ");
      scanf( "%d", &cy);
      cy = max_y - cy;

      cleardevice();
      setbkcolor(WHITE);

      setcolor(GREEN);
      setlinestyle(SOLID_LINE, 0, 3);
      drawpoly( edges, figure );
      getch();

      for(int i=0; i < edges; i++)
            figure[2*i+1] = max_y - figure[2*i+1];
      rotate(figure,edges,angle,cx,cy);
      for(int i=0; i < edges; i++)
            figure[2*i+1] = max_y - figure[2*i+1];

      setcolor(RED);
      drawpoly( edges, figure );
      getch();
}


/*Function:
void rotate( int figure[], int edges, double angle, int cx, int cy )
{
      double x, y;
      angle = -1 * (angle*3.14/180);
      double cos_a = cos(angle);
      double sin_a = sin(angle);

      for(int i=0; i < edges; i++)
      {
            x = figure[2*i] - cx;
            y = figure[2*i+1] - cy;
            figure[2*i] = floor( (* cos_a) - (* sin_a) + cx + 0.5 );
            figure[2*i+1] = floor( (* sin_a)+(* cos_a) + cy + 0.5 );
      }
} */
Output:
1.Enter Co-ordinates
2.Actual Image

3.Rotating Image


/*Boundry Fill Algorithm in Computer graphics with output*/

Boundry Fill Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>

void boundary_fill(int x, int y, int fcolor, int bcolor)
{

    if ((getpixel(x, y) != fcolor) && (getpixel(x, y) != bcolor)) {
       putpixel(x, y, fcolor);
       boundary_fill(x + 1, y, fcolor, bcolor);
       boundary_fill(x - 1, y, fcolor, bcolor);
       boundary_fill(x, y - 1, fcolor, bcolor);
       boundary_fill(x, y + 1, fcolor, bcolor);
       boundary_fill(x + 1, y - 1, fcolor, bcolor);
       boundary_fill(x + 1, y + 1, fcolor, bcolor);
       boundary_fill(x - 1, y - 1, fcolor, bcolor);
       boundary_fill(x - 1, y + 1, fcolor, bcolor);
    }
}


void main()
{
    int x, y, fcolor, bcolor;

    clrscr();
    printf("Enter the seed point (x,y) : ");
    scanf("%d%d", &x, &y);
    printf("Enter boundary color : ");
    scanf("%d", &bcolor);
    printf("Enter new color : ");
    scanf("%d", &fcolor);

    int gd = DETECT, gm = DETECT;
    initgraph(&gd, &gm, "");
    cleardevice();
    boundary_fill(x, y, fcolor, bcolor);

    getch();
}




Output: