Sunday 20 September 2015

Man In Middle Attack Program In Android









package com.example.dellfie;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;


import android.app.Activity;

public class man_in_middle_attack  extends Activity implements OnClickListener {

Button b11;
EditText alice_1,bob_1,tom_a_1,tom_b_1;
int n=11;
int g=7;
int x,y,tomx,tomy,alice_k1,tom_k1,tom_k2,bob_k2;
TextView k1,k2,k11,k22;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.man_in_middle_attack);
b11=(Button) findViewById(R.id.cal_man);
b11.setOnClickListener(this);
alice_1=(EditText) findViewById(R.id.edi_alice_man);
bob_1=(EditText) findViewById(R.id.edi_bob_man);
tom_a_1=(EditText) findViewById(R.id.edi_tom_a_man);
tom_b_1=(EditText) findViewById(R.id.edi_tom_b_man);
k1=(TextView) findViewById(R.id.txt_alice_k1);
k2=(TextView) findViewById(R.id.txt_bob_k2);
k11=(TextView) findViewById(R.id.txt_tom_k1);
k22=(TextView) findViewById(R.id.txt_tom_k2);
}


@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(arg0.getId()==R.id.cal_man)
{
x=Integer.parseInt(alice_1.getText().toString());
y=Integer.parseInt(bob_1.getText().toString());
tomx=Integer.parseInt(tom_a_1.getText().toString());
tomy=Integer.parseInt(tom_b_1.getText().toString());

int alice_1=(int) Math.pow(g,x);
int alice_2=alice_1%n;
Toast.makeText(getApplicationContext(), alice_2+"",Toast.LENGTH_LONG).show();
int bob_1=(int) Math.pow(g,y);
int bob_2=bob_1%n;
Toast.makeText(getApplicationContext(), bob_2+"",Toast.LENGTH_LONG).show();



int tom_1=(int) Math.pow(g,tomx);
int tom_1_1=tom_1%n;
Toast.makeText(getApplicationContext(), "Tom A value is" +tom_1_1,Toast.LENGTH_LONG).show();

int tom_b_1=(int) Math.pow(g,tomy);
int tom_b_1_1=tom_b_1%n;
Toast.makeText(getApplicationContext(),"Tom B value is" + tom_b_1_1,Toast.LENGTH_LONG).show();

int alice_k1_1=(int) Math.pow(tom_b_1_1,x);
int alice_k1_1_2=alice_k1_1%n;
Toast.makeText(getApplicationContext(), "alice k1 "+alice_k1_1_2,Toast.LENGTH_LONG).show();
k1.setText(alice_k1_1_2+"");


int bob_k2_1=(int) Math.pow(tom_1_1,y);
int bob_k2_1_2=bob_k2_1%n;
Toast.makeText(getApplicationContext(), "bob k2 "+bob_k2_1_2,Toast.LENGTH_LONG).show();
k2.setText(bob_k2_1_2+"");

int tom_k1_1=(int) Math.pow(bob_2,tomx);
int tom_k1_1_2=tom_k1_1%n;
Toast.makeText(getApplicationContext(), "tom k1 "+tom_k1_1_2,Toast.LENGTH_LONG).show();

k11.setText(tom_k1_1_2+"");

int tom_k2_1=(int) Math.pow(alice_2,tomy);
int tom_k2_1_2=tom_k2_1%n;
Toast.makeText(getApplicationContext(), "tom k2 "+tom_k2_1_2,Toast.LENGTH_LONG).show();
k22.setText(tom_k2_1_2+"");
}
}
}