Professional Documents
Culture Documents
The security of many public key encryption schemes relied on the intractability of finding the
integer factoring problem such as the RSA scheme. However, there is a great deal of research
concerning factoring the RSA modulus. Factoring the modulus is very hard and therefore an
efficient and fast algorithm is required to solve this problem. The suggested algorithm aims to
obtain the private key by factoring the modulus based the public key of the RSA scheme. This
new idea is claimed to be more efficient than the existing algorithms especially when the public
key is small, since most public key encryption system use small keys to improve the efficiency of
encryption.
We have developed a program, with a GUI made in C++ using wxWidgets, to implement the
proposed algorithm for cracking the RSA scheme.
Existing RSA algorithm:
RSA involves a public key and a private key. The public key can be known to everyone and is
used for encrypting messages. Messages encrypted with the public key can only be decrypted
using the private key. The keys for the RSA algorithm are generated the following way:
1. Choose two distinct prime numbers p and q.
o For security purposes, the integers p and q should be chosen at random, and
should be of similar bit-length. Prime integers can be efficiently found using a
primality test.
2. Compute n = pq.
o n is used as the modulus for both the public and private keys
3. Compute φ(n) = (p – 1)(q – 1), where φ is Euler's totient function.
4. Choose an integer e such that 1 < e < φ(n) and gcd(e,φ(n)) = 1, i.e. e and φ(n) are
coprime.
o e is released as the public key exponent.
5. Determine d = e–1 mod φ(n); i.e. d is the multiplicative inverse of e mod φ(n).
o This is often computed using the extended Euclidean algorithm.
o d is kept as the private key exponent.
The public key consists of the modulus n and the public (or encryption) exponent e. The private
key consists of the private (or decryption) exponent d which must be kept secret.
Example
1. Choose two distinct prime numbers, such as
p = 61 and q = 53.
2. Compute n = pq giving
n = 61 · 53 = 3233.
3. Compute the totient of the product as φ(n) = (p − 1)(q − 1) giving
φ(3233) = (61 − 1)(53 − 1) = 3120.
4. Choose any number 1 < e < 3120 that is coprime to 3120. Choosing a prime number for e
leaves us only to check that e is not a divisor of 3120.
Let e = 17.
5. Compute d, the modular multiplicative inverse of yielding
d = 2753.
The public key is (n = 3233, e = 17). For a padded plaintext message m, the encryption function
is m17 (mod 3233).
The private key is (n = 3233, d = 2753). For an encrypted ciphertext c, the decryption function is
c2753 (mod 3233).
For instance, in order to encrypt m = 65, we calculate
c = 6517 (mod 3233) = 2790.
To decrypt c = 2790, we calculate
m = 27902753 (mod 3233) = 65.
c.ii. qi=[1/ri-1]
c.iii. ri=(1/ri-1)-qi
c.iv. if(qi=qi-1)
c.iv.1. break
f=(q0,q1,q2,…)
b. If i is even
d. If i is odd
Gui.cpp:
#include<wx/wx.h>
#include<iostream>
#include<cstring>
#include "rsacrack.cpp"
public:
};
IMPLEMENT_APP(RSAKiller)
public:
};
dialog::dialog(const wxString &title, const wxPoint &pos, const
wxSize &size)
:wxDialog(NULL,-1,title,pos,size)
this->SetSizeHints(wxDefaultSize,wxDefaultSize);
encodeSizer->Add(label_encode,0,wxALL,5);
this->SetSizer(encodeSizer);
this->Layout();
public:
wxStaticText *introText;
wxTextCtrl *codeword;
wxTextCtrl *publickeyfields;
//cout<<"Decode pressed"<<endl;
cout<<codeword->GetValue().utf8_str()<<endl;
if(strcmp(codeword->GetValue().char_str(),"Enter
Number")==0)
return;
cout<<publickeyfields->GetValue().utf8_str()<<endl;int
e,n;
if(!sscanf(publickeyfields-
>GetValue().utf8_str(),"(%d,%d)",&e,&n))
return;
int cw=0;
sscanf(codeword->GetValue().utf8_str(),"%d",&cw);
int k=attack(n,e,cw);
/*char *output;
for(int i=0;i<strlen(output);i++)
outputstring[i]=output[i];
outputstring[i]='\0';
//wxMessageBox(codeword->GetValue(),_T("Decoded"));
wxMessageBox(mystring,_T("Decoded"));
cout<<"("<<e<<","<<n<<")"<<endl;
//dialog *encode=new
dialog(_("Encode"),wxPoint(100,100),wxDefaultSize);
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(InfoFrame,wxFrame)
END_EVENT_TABLE()
enum
ID_QUIT=1,
ID_ABOUT
};
bool RSAKiller::OnInit()
{
InfoFrame *encodeFrame = new InfoFrame(_("RSA Killer
v1.0"), wxPoint(100,100), wxSize(450,350));
encodeFrame->Connect(ID_ABOUT, wxEVT_COMMAND_MENU_SELECTED,
(wxObjectEventFunction) &InfoFrame::OnAbout);
encodeFrame->Show(true);
SetTopWindow(encodeFrame);
return true;
fileMenu->Append(ID_ABOUT,_("&About..."));
fileMenu->AppendSeparator();
fileMenu->Append(ID_QUIT,_("&Exit"));
menuBar->Append(fileMenu, _("&File"));
SetMenuBar(menuBar);
CreateStatusBar();
wxPoint(10,90), wxSize(140,wxDefaultCoord),
wxTE_READONLY );
//level2Text->Add(m_readonly,1);
//wxSizerFlags(1).Expand().Border(
wxALL, 5));
//SetSizer(level2Text);
publickey->Add(publickeyfields);
encodeFields->Add(new wxStaticText(this,-1,_T("Enter
codeword")),wxSizerFlags(1).Expand().Border(wxALL,5));
codeword=new wxTextCtrl(this,wxID_ANY,_T("Enter
number"),wxDefaultPosition,wxDefaultSize);
encodeFields-
>Add(codeword,wxSizerFlags(1).Expand().Border(wxALL,5));
//topsizer->Add(encodeFields);
topsizer-
>Add(level2Text,wxSizerFlags(1).Expand().Border(wxALL,10));
topsizer-
>Add(publickey);//,wxSizerFlags(1).Expand().Border(wxALL,10));
topsizer->Add(encodeFields);
buttons->Add(new
wxButton(this,DECODE,_T("Decode")),wxSizerFlags().Border(wxALL,7
));
//buttons->Add(new
wxButton(this,ENCODE,_T("Encode")),wxSizerFlags().Border(wxALL,7
));
topsizer->Add(buttons,wxSizerFlags().Center());
SetSizerAndFit(topsizer);
//topsizer->SetSizeHints(this);
Close(true);
wxOK|wxICON_INFORMATION,this);
Rsacrack.cpp:
#include<iostream>
#include<vector>
int main()
int e=2621,n=8927;
int m=0;
cout<<"Starting ..."<<endl;
vector<int> q;
vector<double> r;
q.push_back(e/n);
r.push_back(double(e)/double(n));
//cout<<q[0]<<"__"<<double(e)/double(n)<<endl;
while(1)
q.push_back((int)(1.0/r.at(r.size()-1)));
r.push_back((1.0/r.at(r.size()-1))-q.at(q.size()-1));
if(q.at(q.size()-1)==q.at(q.size()-2))
break;
//cout<<q[q.size()-1]<<endl;
for(vector<int>::iterator i=q.begin();i!=q.end();i++)
cout<<*i<<" ";
cout<<endl;
return 0;
Screenshot:
// RSA attack algorithm as implemented on devcpp
#include<iostream>
#include<vector>
#include<conio.h>
#include<math.h>
//cout<<x<<endl;
//cout<<c<<endl;
int y=e%9;
for(int i=0;i<e-y-9;i+=9)
c=(c*x)%n;
x=pow(m,y);
c=(c*x)%n;
//cout<<c<<endl;
return c;
vector<int> q;
vector<double> r;
vector<int> nn,dg,g,d;
q.push_back(e/n);
r.push_back(((double)e/(double)n));
cout<<q[0]<<"__"<<r[0]<<endl;
int m=0;
while(1)
m+=1;
q.push_back(1/r[r.size()-1]);
r.push_back((1/r[r.size()-1])-q[q.size()-1]);
if(q[q.size()-1]==q[q.size()-2])
break;
for(int i=0;i<r.size();i++)
cout<<q[i]<<"-->"<<r[i]<<endl;
nn.push_back(1);dg.push_back(1);
cout<<nn[0]<<' '<<dg[0]<<endl;
nn.push_back(q[0]*q[1]+1);dg.push_back(q[1]);
for(int j=2;j<=m;j++)
nn.push_back(q[j]*nn[j-1]+nn[j-2]);
dg.push_back(q[j-1]*dg[j-1]+dg[j-2]);
cout<<nn[j-1]<<' '<<dg[j-1]<<endl;
}
for(int k=0;k<m;k++)
g.push_back((e*dg[k])%nn[k]);
cout<<g[k]<<endl;
int dd;
for(int k=0;k<g.size();k++)
if(g[k]!=0)
dd=dg[k]/g[k];
cout<<dd<<endl;
for(int k=0;k<dd-2;k++)
retv=(retv*c)%n;
retv=retv%n;
return retv;
int main()
int n,e,m;
cout<<" enter the message along with the public keys ";
cin>>m>>n>>e;
int c=encrypt(m,n,e);
int retv=attack(m,n,e);
getch();
return 0;