本文介绍了使用RSA算法的密码学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不使用密码学类的情况下对任何字符串进行加密和解密(使用RSA算法)我写了一个代码,请告诉我我的错误在哪里我做错了....

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....

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);

}

推荐答案


这篇关于使用RSA算法的密码学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-13 01:19