Click here to Skip to main content
15,896,500 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to encrypt and decrypt (using RSA algorithm) any string without using cryptography classes i wrote a code please tell me about my mistake where i do wrong....
C#
protected void Button1_Click(object sender, EventArgs e)
{
    string ab;

    int unicode = 0, a = 0, cnt = 0, i = 0, j = 0;
    int[] number=new int[1000];
    double[] c1=new double[1000];
    double[] unicode1 = new double[1000];
     
    ab = TextBox1.Text;
    double d;

    foreach (char c in ab)
    {        
        unicode = c;
        Console.WriteLine(unicode < 128 ? ASCII:{0} : NON-ASCII:{0}, unicode);
        number[i] = unicode;
        i++;
    }
    
    double p = 0, q = 0, o = 0;

    p = (double)Convert.ToInt64(TextBox2.Text);
    q = (double)Convert.ToInt64(TextBox3.Text);
    
    double n = p * q;
    double q1 = (p - 1) * (q - 1);

    Response.Write(q1);

    o = (double)Convert.ToInt64(TextBox4.Text);
    d = (Math.Pow(o, -1));
    d = d % q1;
    
    for (j = 0; j< i; j++)
    {
        c1[j]=(Math.Pow(number[j],n))%n;
        Response.Write(c1[j]);
    }
 
    for (j = 0; j<i;>    
    {
        unicode1[j]=(Math.Pow(c1[j],d))%n;
        Response.Write("unicode1" + unicode1[j]);
    }
    double unicode1 = (int)(Math.Pow(c1,d)) % n;
    
    for (j = 0; j<i;>    
    {
        string str = char.ConvertFromUtf32((int)unicode1[j]);
        Response.Write(str);
    }
    string str = char.ConvertFromUtf32((int)unicode);

    Response.Write(str);

}
Posted
Updated 3-Oct-12 4:03am
v2

1 solution

Should probably use the built-in RSACryptoServiceProvider class :-)
see Public Key RSA Encryption in C# .NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900