vb点虐 rsa算法 vbnet randomize

怎么用vb实现rsa算法?谢谢了,大神帮忙啊

Private Sub Command3_Click() Dim ni%, m1%, m%, n%, r% n1 = Text1.Text m1 = Text2.Text If m1 n1 Then ' mn m = m1: n = n1 Else m = n1: n = m1 End If Do r = m Mod n If r = 0 Then Exit Do m = n n = r Loop Text3.Text = n Text4.Text = m1 * n1 / n End Sub

目前累计服务客户上千多家,积累了丰富的产品开发及服务经验。以网站设计水平和技术实力,树立企业形象,为客户提供成都网站制作、成都网站设计、外贸营销网站建设、网站策划、网页设计、网络营销、VI设计、网站改版、漏洞修补等服务。创新互联公司始终以务实、诚信为根本,不断创新和提高建站品质,通过对领先技术的掌握、对创意设计的研究、对客户形象的视觉传递、对应用系统的结合,为客户提供更好的一站式互联网解决方案,携手广大客户,共同发展进步。

vb点虐 中实现rsa加密解密 急!急!

我觉得你的并不是RSA加密解密算法。

在点虐 的有一个System.Security.Cryptography的命名空间,里面有一RSACryptoServiceProvider的类用来对byte进行RSA加密解密。

具体例子如下:

using System;

using System.Security.Cryptography;

using System.Text;

class RSACSPSample

{

static void Main()

{

try

{

//Create a UnicodeEncoder to convert between byte array and string.

UnicodeEncoding ByteConverter = new UnicodeEncoding();

//Create byte arrays to hold original, encrypted, and decrypted data.

byte[] dataToEncrypt = ByteConverter.GetBytes("Data to Encrypt");

byte[] encryptedData;

byte[] decryptedData;

//Create a new instance of RSACryptoServiceProvider to generate

//public and private key data.

RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

//Pass the data to ENCRYPT, the public key information

//(using RSACryptoServiceProvider.ExportParameters(false),

//and a boolean flag specifying no OAEP padding.

encryptedData = RSAEncrypt(dataToEncrypt,RSA.ExportParameters(false), false);

//Pass the data to DECRYPT, the private key information

//(using RSACryptoServiceProvider.ExportParameters(true),

//and a boolean flag specifying no OAEP padding.

decryptedData = RSADecrypt(encryptedData,RSA.ExportParameters(true), false);

//Display the decrypted plaintext to the console.

Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData));

}

catch(ArgumentNullException)

{

//Catch this exception in case the encryption did

//not succeed.

Console.WriteLine("Encryption failed.");

}

}

static public byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)

{

try

{

//Create a new instance of RSACryptoServiceProvider.

RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

//Import the RSA Key information. This only needs

//toinclude the public key information.

RSA.ImportParameters(RSAKeyInfo);

//Encrypt the passed byte array and specify OAEP padding.

//OAEP padding is only available on Microsoft Windows XP or

//later.

return RSA.Encrypt(DataToEncrypt, DoOAEPPadding);

}

//Catch and display a CryptographicException

//to the console.

catch(CryptographicException e)

{

Console.WriteLine(e.Message);

return null;

}

}

static public byte[] RSADecrypt(byte[] DataToDecrypt, RSAParameters RSAKeyInfo,bool DoOAEPPadding)

{

try

{

//Create a new instance of RSACryptoServiceProvider.

RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

//Import the RSA Key information. This needs

//to include the private key information.

RSA.ImportParameters(RSAKeyInfo);

//Decrypt the passed byte array and specify OAEP padding.

//OAEP padding is only available on Microsoft Windows XP or

//later.

return RSA.Decrypt(DataToDecrypt, DoOAEPPadding);

}

//Catch and display a CryptographicException

//to the console.

catch(CryptographicException e)

{

Console.WriteLine(e.ToString());

return null;

}

}

}

[Visual Basic]

Try

'Create a new RSACryptoServiceProvider object.

Dim RSA As New RSACryptoServiceProvider()

'Export the key information to an RSAParameters object.

'Pass false to export the public key information or pass

'true to export public and private key information.

Dim RSAParams As RSAParameters = RSA.ExportParameters(False)

Catch e As CryptographicException

'Catch this exception in case the encryption did

'not succeed.

Console.WriteLine(e.Message)

End Try

[C#]

try

{

//Create a new RSACryptoServiceProvider object.

RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

//Export the key information to an RSAParameters object.

//Pass false to export the public key information or pass

//true to export public and private key information.

RSAParameters RSAParams = RSA.ExportParameters(false);

}

catch(CryptographicException e)

{

//Catch this exception in case the encryption did

//not succeed.

Console.WriteLine(e.Message);

}

关于vb做的rsa加解密程序

:将方程x^4-px^3+q=0移项,得

x^4+q=px^3

可见,x^4≥0,则x^4+q0,所以px^30,即x0,本题也就是要求出使方程x^4-px^3+q=0有正整数解的素数p、q;

且素数p必定是奇素数,否则是偶素数的话,那么p=2,则方程成为:x^4+q=2x^3,即q=2x^3-x^4=x^3×(2-x)0,得出2-x0,即x2,则只能是x=1,代入方程:1^4+q=2×1^3,即1+q=2,解得q=1,不是素数,故p必定是奇素数。

分两种情形讨论:

情形一:当x为偶数时,设为x=2n,则有

(2n)^4+q=p×(2n)^3

16n^4+q=p×8n^3

上式右端是偶数,则左端的q必须为偶数,否则:左端奇偶相加得奇,不符。

而q作为素数,唯一的偶素数就是2,即q=2,则上式成为

16n^4+2=p×8n^3

两边同时除以2,得:8n^4+1=p×4n^3,显然,左端奇偶相加得奇,但右端为偶,矛盾。所以方程无偶整数解;

情形二:当x为奇数时,设为x=2n-1,则有

(2n-1)^4+q=p×(2n-1)^3

观察上式,右端为奇,则左端也必须为奇,而(2n-1)^4是奇,所以得出q必须为偶,故素数q=2,上式成为:

(2n-1)^4+2=p×(2n-1)^3,整理成:

p(2n-1)^3-(2n-1)^4=(2n-1)^3×[p-(2n-1)]=1×2

由于(2n-1)^3为奇,所以必有:(2n-1)^3=1,解得:n=1;

则:[p-(2n-1)]=2,解得:p=3;

综上,对于素数p、q,方程x^4-px^3+q=0有整数解,则p、q分别为3和2。

晕,再补一个!

1:编程实现 自动生成两个素数p,q

2:编程实现 计算n=p*q

f(n)=(p-1)(q-1)

3: 随机数e满足:0ef(n) and f(n)与e互为素数

4: 编程实现 计算d:d=e mod f(n)=1

如要加密m

5:编程实现计算c:

加密公式:c=m^e mod n

6:编程实现解密m:

解密公式:m=c^d mod n

Private Sub Command10_Click()

End

End Sub

Private Sub Command9_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Text4.Text = ""

Text5.Text = ""

Text6.Text = ""

Text7.Text = ""

Text8.Text = ""

Text9.Text = ""

End Sub

Private Sub Command2_Click()

p = Val(Text1.Text)

q = Val(Text2.Text)

Text3.Text = Str$(p * q)

End Sub

Private Sub Command3_Click()

p = Val(Text1.Text)

q = Val(Text2.Text)

Text4.Text = Str$(p - 1) * (q - 1)

End Sub


网站名称:vb点虐 rsa算法 vbnet randomize
分享网址:http://azwzsj.com/article/ddgehsi.html