Program to implement RSA(Ron Rivest, Adi Shamir and Len Adleman, who invented it in 1977 [RIVE78]).

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<math.h>
#include<string.h>
void main()
{
    int a, b, i, j, t, x, n, k = 0, flag = 0, prime[100];
    char m[20], pp[20];
    float p[20], c[20];
    double e, d;
    clrscr();
    for(i = 0; i < 50; i++)
    {
        flag = 0;
        for(j = 2; j < i / 2; j++)
            if(i % j == 0)
            {
                flag = 1;
                break;
            }
            if(flag == 0)
                prime[k++] = i;
    }
    a = prime[k - 1];
    b = prime[k - 2];
    n = a * b;
    t = (a - 1) * (b - 1);
    e=(double)prime[2];
    d=1 / (float)e;
    printf("\nKey of encryption is:%lf", d);
    printf("\nEnter the text:");
    scanf("%s", &m);
    x = strlen(m);
    printf("\nSource------------destination");
    printf("\nChar\tnumeric\tcipher\t\tnumeric\t\tchar\n");
    for(i = 0; i < x; i++)
    {
        printf("%c", m[i]);
        printf("\t%d", m[i] - 97);
        c[i] = pow(m[i] - 97, (float)e);
        c[i] = fmod(c[i], (float)n);
        printf("\t%f", c[i]);
        p[i] = pow(c[i], (float)d);
        p[i] = fmod(p[i], (float)n);
        printf("\t%f", p[i]);
        pp[i] = p[i] + 97;
        printf("\t%c\n", pp[i]);
    }
    getch();
 }

Output:

Key of encryption is:0.500000
Enter the text:geethanjali

Source------------destination
Char    numeric  cipher          numeric         char
g       6        36.000000       6.000000        g
e       4        16.000000       4.000000        e
e       4        16.000000       4.000000        e
t       19       361.000000      19.000000       t
h       7        49.000000       7.000000        h
a       0        0.000000        0.000000        a
n       13       169.000000      13.000000       n
j       9        81.000000       9.000000        j
a       0        0.000000        0.000000        a
l       11       121.000000      11.000000       l
i       8        64.000000       8.000000        i