You are on page 1of 16

Abstract:

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.

Proposed attack algorithm

1. Obtain entity A public key (e,n)


2. Compute qi and ri as follows:
a. f = (e/n)
b. q0 = [f], r0=f-q0, m=0
c. for =1,2…
c.i. m=m+1

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,…)

3. Compute k/(d*g) as follows:

a. For i=1,2,3…m (m is obtained from the above step)

b. If i is even

c. Reconstruct f using algorithm 1 using the expansion q0,q1,..qi-1,qi+1

d. If i is odd

e. Reconstruct f using the expansion q0,q1,…qi)

So k/(d*g)=(nm/dm) is each iteration

4. Compute d=(d*g)/g. Using this, we can break the message.


Code

Gui.cpp:

#include<wx/wx.h>

#include<iostream>

#include<cstring>

#include "rsacrack.cpp"

#define DECODE 101

#define ENCODE 102

using namespace std;

class RSAKiller:public wxApp

public:

virtual bool OnInit();

};

IMPLEMENT_APP(RSAKiller)

class dialog:public wxDialog

public:

dialog(const wxString &title, const wxPoint &pos, const


wxSize &size);

};
dialog::dialog(const wxString &title, const wxPoint &pos, const
wxSize &size)

:wxDialog(NULL,-1,title,pos,size)

this->SetSizeHints(wxDefaultSize,wxDefaultSize);

wxBoxSizer *encodeSizer = new wxBoxSizer(wxVERTICAL);

wxStaticText *label_encode=new wxStaticText(this, -1,


wxT("Enter ciphertext"), wxPoint(100,100));

encodeSizer->Add(label_encode,0,wxALL,5);

this->SetSizer(encodeSizer);

this->Layout();

class InfoFrame:public wxFrame

public:

InfoFrame(const wxString &title, const wxPoint &pos, const


wxSize &size);

wxStaticText *introText;

wxTextCtrl *codeword;

wxTextCtrl *publickeyfields;

void OnQuit(wxCommandEvent &Event);

void OnAbout(wxCommandEvent &Event);


void OnDecode(wxCommandEvent &Event)

//cout<<"Decode pressed"<<endl;

cout<<codeword->GetValue().utf8_str()<<endl;

if(strcmp(codeword->GetValue().char_str(),"Enter
Number")==0)

wxMessageBox(_T("You must enter a


number"),_T("Error"));

return;

cout<<publickeyfields->GetValue().utf8_str()<<endl;int
e,n;

if(!sscanf(publickeyfields-
>GetValue().utf8_str(),"(%d,%d)",&e,&n))

wxMessageBox(_T("You must enter public


key"),_T("Error"));

return;

int cw=0;

sscanf(codeword->GetValue().utf8_str(),"%d",&cw);

int k=attack(n,e,cw);

/*char *output;

sprintf(output,"The original plaintext was


%d",k);string outputstring;

for(int i=0;i<strlen(output);i++)

outputstring[i]=output[i];
outputstring[i]='\0';

*/ wxString mystring = wxString::Format(wxT("Plaintext was


%i"),k);

//wxMessageBox(codeword->GetValue(),_T("Decoded"));

wxMessageBox(mystring,_T("Decoded"));

//cout<<"Decoded -> "<<output<<endl;

cout<<"("<<e<<","<<n<<")"<<endl;

//dialog *encode=new
dialog(_("Encode"),wxPoint(100,100),wxDefaultSize);

DECLARE_EVENT_TABLE()

};

BEGIN_EVENT_TABLE(InfoFrame,wxFrame)

EVT_BUTTON (DECODE, InfoFrame::OnDecode)

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_QUIT, wxEVT_COMMAND_MENU_SELECTED,


(wxObjectEventFunction) &InfoFrame::OnQuit);

encodeFrame->Connect(ID_ABOUT, wxEVT_COMMAND_MENU_SELECTED,
(wxObjectEventFunction) &InfoFrame::OnAbout);

encodeFrame->Show(true);

SetTopWindow(encodeFrame);

return true;

InfoFrame::InfoFrame(const wxString &title, const wxPoint &pos,


const wxSize &size)

:wxFrame(NULL,-1, title, pos, size)

wxMenuBar *menuBar= new wxMenuBar;

wxMenu *fileMenu = new wxMenu;

fileMenu->Append(ID_ABOUT,_("&About..."));

fileMenu->AppendSeparator();

fileMenu->Append(ID_QUIT,_("&Exit"));

menuBar->Append(fileMenu, _("&File"));

SetMenuBar(menuBar);

CreateStatusBar();

SetStatusText(_("Welcome to RSA Killer v1.0"));

//wxTextDataObject *introText= new


wxTextDataObject(_("Hi"));//new wxTextDataObject(this,-
1,wxT("Hi!"),wxPoint(10,10),wxSize(20,20));

wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);


//wxStaticText *m_readonly = new wxStaticText( this,
wxID_ANY, _T("Simona"),\

wxPoint(10,90), wxSize(140,wxDefaultCoord),
wxTE_READONLY );

wxBoxSizer *level2Text = new wxStaticBoxSizer(new


wxStaticBox(this, wxID_ANY,
_T("Introduction")),wxHORIZONTAL); //Sizer for the intro text
and image

//level2Text->Add(m_readonly,1);

level2Text->Add(new wxStaticText(this, wxID_ANY, _T("Hi!


Welcome to RSA Killer application \ndesigned by Shikhar Kohli
and Salil Saxena")));//,

//wxSizerFlags(1).Expand().Border(
wxALL, 5));

//SetSizer(level2Text);

//wxBoxSizer *level2Buttons = new wxBoxSizer(wxHORIZONTAL);

//level2Text->Add(new wxButton(this, -1 , _T("Encode")), 1);

wxBoxSizer *encodeFields= new wxBoxSizer(wxHORIZONTAL);

wxBoxSizer *publickey = new wxBoxSizer(wxHORIZONTAL);

publickey->Add(new wxStaticText(this,-1,_T("Enter public


key")),wxSizerFlags(1).Expand().Border(wxALL,5));

publickeyfields = new wxTextCtrl(this,-1,_T("in the form


(e,n)"),wxDefaultPosition,wxSize(150,25));

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

wxBoxSizer *buttons=new wxBoxSizer(wxHORIZONTAL);

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

//Uncomment this later if needed

//topsizer->SetSizeHints(this);

void InfoFrame::OnQuit(wxCommandEvent &WXUNUSED(event))

Close(true);

void InfoFrame::OnAbout(wxCommandEvent &WXUNUSED(event))


{

wxMessageBox(_("RSA Killer by Shikhar Kohli (751/IT/08) &


Salil Saxena (749/IT/08)"),

_("About RSA Killer"),

wxOK|wxICON_INFORMATION,this);

Rsacrack.cpp:

#include<iostream>

#include<vector>

using namespace std;

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)

//cout<<"In loop ";


m+=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>

using namespace std;

long int encrypt(int m,int n,int e)

long int x=pow(m,9);

//cout<<x<<endl;

long int c=x%n;

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

int attack(int c,int n,int e)

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;

//generating q and r vectors

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;

//generating n and dg vectors

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;

//decryption: final stage of the attack algorithm

long int retv=(c*c)%n;

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

cout<<" The cipher-text is : "<<c<<endl;

int retv=attack(m,n,e);

//the decrypted message

cout<<" the retrieved message from the cipher-text is : "<<retv<<endl;

getch();

return 0;

You might also like