:將方程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
RSA算法非常簡單,概述如下:
找兩素數p和q
取n=p*q
取t=(p-1)*(q-1)
取任何一個數e,要求滿足et并且e與t互素(就是最大公因數為1)
取d*e%t==1
這樣最終得到三個數: n d e
設消息為數M (M n)
設c=(M**d)%n就得到了加密后的消息c
設m=(c**e)%n則 m == M,從而完成對c的解密。
注:**表示次方,上面兩式中的d和e可以互換。
在對稱加密中:
n d兩個數構成公鑰,可以告訴別人;
n e兩個數構成私鑰,e自己保留,不讓任何人知道。
給別人發送的信息使用e加密,只要別人能用d解開就證明信息是由你發送的,構成了簽名機制。
別人給你發送信息時使用d加密,這樣只有擁有e的你能夠對其解密。
rsa的安全性在于對于一個大數n,沒有有效的方法能夠將其分解
從而在已知n d的情況下無法獲得e;同樣在已知n e的情況下無法
求得d。
二實踐
接下來我們來一個實踐,看看實際的操作:
找兩個素數:
p=47
q=59
這樣
n=p*q=2773
t=(p-1)*(q-1)=2668
取e=63,滿足et并且e和t互素
用perl簡單窮舉可以獲得滿主 e*d%t ==1的數d:
C:\Tempperl -e "foreach $i (1..9999){ print($i),last if $i*63%2668==1 }"
847
即d=847
最終我們獲得關鍵的
n=2773
d=847
e=63
取消息M=244我們看看
加密:
c=M**d%n = 244**847%2773
用perl的大數計算來算一下:
C:\Tempperl -Mbigint -e "print 244**847%2773"
465
即用d對M加密后獲得加密信息c=465
解密:
我們可以用e來對加密后的c進行解密,還原M:
m=c**e%n=465**63%2773 :
C:\Tempperl -Mbigint -e "print 465**63%2773"
244
即用e對c解密后獲得m=244 , 該值和原始信息M相等。
三字符串加密
把上面的過程集成一下我們就能實現一個對字符串加密解密的示例了。
每次取字符串中的一個字符的ascii值作為M進行計算,其輸出為加密后16進制
的數的字符串形式,按3字節表示,如01F
代碼如下:
#!/usr/bin/perl -w
#RSA 計算過程學習程序編寫的測試程序
#watercloud 2003-8-12
#
use strict;
use Math::BigInt;
my %RSA_CORE = (n=2773,e=63,d=847); #p=47,q=59
my $N=new Math::BigInt($RSA_CORE{n});
my $E=new Math::BigInt($RSA_CORE{e});
my $D=new Math::BigInt($RSA_COREfhh1fh1);
print "N=$N D=$D E=$E\n";
sub RSA_ENCRYPT
{
my $r_mess = shift @_;
my ($c,$i,$M,$C,$cmess);
for($i=0;$i length($$r_mess);$i++)
{
$c=ord(substr($$r_mess,$i,1));
$M=Math::BigInt-new($c);
$C=$M-copy(); $C-bmodpow($D,$N);
$c=sprintf "%03X",$C;
$cmess.=$c;
}
return \$cmess;
}
sub RSA_DECRYPT
{
my $r_mess = shift @_;
my ($c,$i,$M,$C,$dmess);
for($i=0;$i length($$r_mess);$i+=3)
{
$c=substr($$r_mess,$i,3);
$c=hex($c);
$M=Math::BigInt-new($c);
$C=$M-copy(); $C-bmodpow($E,$N);
$c=chr($C);
$dmess.=$c;
}
return \$dmess;
}
my $mess="RSA 娃哈哈哈~~~";
$mess=$ARGV[0] if @ARGV = 1;
print "原始串:",$mess,"\n";
my $r_cmess = RSA_ENCRYPT(\$mess);
print "加密串:",$$r_cmess,"\n";
my $r_dmess = RSA_DECRYPT($r_cmess);
print "解密串:",$$r_dmess,"\n";
#EOF
測試一下:
C:\Tempperl rsa-test.pl
N=2773 D=847 E=63
原始串:RSA 娃哈哈哈~~~
加密串:5CB6CD6BC58A7709470AA74A0AA74A0AA74A6C70A46C70A46C70A4
解密串:RSA 娃哈哈哈~~~
C:\Tempperl rsa-test.pl 安全焦點(xfocus)
N=2773 D=847 E=63
原始串:安全焦點(xfocus)
加密串:3393EC12F0A466E0AA9510D025D7BA0712DC3379F47D51C325D67B
解密串:安全焦點(xfocus)
我覺得你的并不是RSA加密解密算法。
在.net的有一個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.netrsa加密 net rsa加密
網站路徑:http://www.yijiale78.com/article46/hihihg.html
成都網站建設公司_創新互聯,為您提供網站設計、商城網站、響應式網站、定制開發、外貿網站建設、網站策劃
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯