Sunday 20 September 2015

Selection Sort Program in Android



package com.example.dellfie;


import android.app.Activity;
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;

public class selection_sort extends Activity implements OnClickListener{
EditText txt1;
TextView txtview1;
Button b11;
int min;
String arr11;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selection_sort);

txt1=(EditText) findViewById(R.id.txt_selection_sort);
b11=(Button) findViewById(R.id.b_selection_sort);
txtview1=(TextView) findViewById(R.id.txtselect_result);
b11.setOnClickListener(this);



}

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stubty

try
{

String str1=txt1.getText().toString();
String[] items = str1.replaceAll("\\[", "").replaceAll("\\]", "").split(",");

int[] results = new int[items.length];
if(arg0.getId()==R.id.b_selection_sort)
{
for(int i = 0;i<items.length;i++)
   {
       //Assume first element is min
       min = i;
       for(int j = i + 1;j<items.length;j++)
       {
           if(Integer.parseInt(items[j]) < Integer.parseInt(items[min])) { min = j;}
       }
       int temp = Integer.parseInt(items[i]);
      items[i] = items[min];
       items[min]= temp+"";
     
 

Toast.makeText(getApplicationContext(),items[i],Toast.LENGTH_LONG ).show();
String str11= txtview1.getText().toString();

txtview1.setText(str11+","+items[i].toString());
 
   }
}

}
catch(Exception ee)
{

}
}
}

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+"");
}
}
}