Find us on Google+ Kill the code: secure
Showing posts with label secure. Show all posts
Showing posts with label secure. Show all posts

Wednesday, 7 March 2012

Ball rolling in the TUNNEL


/* Make the ball float in tunnel and apply password mechanism...*/


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="rolling_fun12" width=1000 height=300>
</applet>
*/


public class rolling_fun12 extends Applet implements Runnable,KeyListener {
String msg="";
String password="nisarg"; /*THIS IS YOUR PASSWORD STRING...*/
char c;
boolean correct=false;
int i=0;
int finish=0;
public void init() {
addKeyListener(this);
requestFocus();
t=new Thread(this);
}
public void keyPressed(KeyEvent ke) {
showStatus("key Pressed.");
/*c=ke.getKeyChar();
check=true;
if(c==password.charAt(i++)) {
msg=msg+c;
}
else {
msg="";
i=0;
}*/
//if(msg.equals(password)) showStatus("VALID PASSWORD.");
//showStatus("key Pressed.");
}
public void keyReleased(KeyEvent ke) {
if(finish==1) showStatus("THE OUTPUT IS ON THE SCREEN.");
else if(msg.equals(password)) {
showStatus("VALID PASSWORD.");
repaint();
}
}
public void keyTyped(KeyEvent ke) {
if(finish==1) showStatus("THE OUTPUT IS ON THE SCREEN.");
else {
showStatus("Key Typed.");
//showStatus("Key Typed.");
c=ke.getKeyChar();
if(c==password.charAt(i++)) {
msg=msg+c;
}
else {
msg="";
i=0;
}
if(msg.equals(password)) {
correct=true;
repaint();
showStatus("VALID PASSWORD.");
}
repaint();
}
}
Thread t;
int start=180;
int end=350;
int x=300;
int y=225;
int end1=0,end2=0,end3=0;
int flag=0,flag2=0;
int slide1=0,drop=0,slide2=0,remain=0,enter=0,once=0;
Color c1=new Color(255,0,255);
/*public void init() {
t=new Thread(this,"first");

}*/

public void start() {
t.start();
}

public void run() {
for(;;) {
if(end3<1460) {
slide2=1;
repaint();
}
else if(end2<1650) {
drop=1;
slide2=0;
repaint();
}
else if(end1<1350) {
drop=0;
slide1=1;
repaint();
}
else {
remain=1;
slide1=0;
slide2=0;
drop=0;
repaint();
}
}
}
public void paint(Graphics g) {
if(correct) {
g.drawLine(15,100,150,100);
g.drawLine(150,100,150,260);
g.drawLine(151,260,325,260);
g.drawLine(200,58,200,218);
g.drawLine(15,58,200,58);
g.drawLine(326,260,326,219);
g.drawLine(326,218,200,218);
if(slide1==1)
{
try {

start=start+15;
end=end+15;
//g.drawArc(x,59,40,40,start,360);
g.setColor(c1);
if(enter==0) {
g.fillArc(x,y,40,40,/*start*/0,360);
enter=1;
}
else {
g.fillArc(x,y,40,40,/*start*/start,353);
enter=0;
}
x=x-5;

if(start>350) {
start=0;
end=350;
}
//if(x>230) x=10;
//if(end1<1350) 
//{
end1+=50;
Thread.sleep(60);
slide1=0;
repaint();
//showStatus("end = "+end);

//}
//flag2=1;
} catch(InterruptedException e) {
showStatus("ERROR");
}
}
if(drop==1) {
try {
start=start+15;
end=end+15;
//x=155;
//y=y+40;
//g.drawArc(x,y,40,40,start,360);
g.setColor(c1);
if(enter==0) {
g.fillArc(x+2,y,40,40,/*start*/0,360);
enter=1;
}
else {
g.fillArc(x+2,y,40,40,/*start*/start,353);
enter=0;
}
y=y-5;

if(start>350) {
start=0;
end=350;
}
//if(y>295) y=150;
//if(end2<700) 
//{
end2+=50;
drop=0;
repaint();
//showStatus("end = "+end);
Thread.sleep(100);
//}
} catch(InterruptedException e) {
showStatus("ERROR");
}
}
if(slide2==1)
{
try {

start=start-15;
end=end+15;
//g.drawArc(x,y-5,40,40,start,360);
g.setColor(c1);
if(enter==1) {
g.fillArc(x,y-5,40,40,/*start*/0,360);
enter=0;
}
else {
g.fillArc(x,y-5,40,40,/*start*/start,353);
x=x-5;
}
if(start>350) {
start=0;
end=350;
}
//if(x>230) x=10;
//if(end1<1350) 
//{
end3+=50;
Thread.sleep(60);
slide1=0;
slide2=0;
repaint();
//showStatus("end = "+end);

//}
//flag2=1;
} catch(InterruptedException e) {
showStatus("ERROR");
}
}
if(remain==1) {
//g.drawArc(x-5,y-5,40,40,0,360);
g.setColor(c1);
finish=1;
if(once==0) {
showStatus("PROGRAM ENDED.");
once=1;
}
g.fillArc(x+5,y,40,40,0,360);
try {
Thread.sleep(500);
} catch(InterruptedException e) {

}
}
}
else {
g.drawString("ENTER VALID PASSWORD.",40,40);
try {
Thread.sleep(3000);
} catch(InterruptedException e) {

}
}
}
}

Sunday, 4 March 2012

Set Password using JAVA

//This program lets you the password and access the data as soon as you type the //correct password..without pressing ENTER...





import java.awt.*;
import java.applet.*;
import java.awt.event.*;


/*
<applet code="password_setter" width=400 height=400>
</applet>
*/


public class password_setter extends Applet implements KeyListener {
String msg="";
String password="PASSWORD";  // Write your Password here....
char c;
boolean correct=false;
int i=0;
public void init() {
addKeyListener(this);
requestFocus();
}
public void keyPressed(KeyEvent ke) {
showStatus("key Pressed.");
/*c=ke.getKeyChar();
check=true;
if(c==password.charAt(i++)) {
msg=msg+c;
}
else {
msg="";
i=0;
}*/
//if(msg.equals(password)) showStatus("VALID PASSWORD.");
//showStatus("key Pressed.");
}
public void keyReleased(KeyEvent ke) {
if(msg.equals(password)) showStatus("VALID PASSWORD.");
}
public void keyTyped(KeyEvent ke) {
showStatus("Key Typed.");
//showStatus("Key Typed.");
c=ke.getKeyChar();
if(c==password.charAt(i++)) {
msg=msg+c;
}
else {
msg="";
i=0;
}
if(msg.equals(password)) {
correct=true;
repaint();
showStatus("VALID PASSWORD.");
}
}
public void paint(Graphics g) {
if(correct) g.drawString("YOU HAVE ENTERED CORRECT PASSWORD.",40,40);
}
}

Monday, 6 February 2012

Play-Fair Cipher in C


/* Play Fair Cipher in C... */



#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,isI=0,l,k=0,start=0,same=0,k1=0;
int i1,j1,i2,j2,i11,jj;
char alph[5][5],chr[25],chr2[25],character,chr1='a',chr_ex[25];
char txt[25],txt2[25];
clrscr();
printf("\nEnter the text : ");
scanf("%s",chr);
for(i=0;i<strlen(chr2);i++) /*TO PREVENT STRING FROM BEING PRINTED WITH GARBAGE CHARACTER...*/
{
chr_ex[i]='-';
}
for(i=0;i<strlen(chr);i++)
{
printf("\nchr[%d] = %c",i+1,chr[i]);
chr_ex[i]=chr[i];
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
alph[i][j]='-';
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
character=chr[++k];
for(l=k-1;l>=0;l--) //FOR REPEATING CHARACTERS...
{
if(character==chr[l])
{
chr[k]='-';
break;
}
}
}
}
k=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(start++<strlen(chr))
if(chr[k]!='-') //FOR i AND j
{
if(chr[k]=='i' || chr[k]=='j')
{
if(isI==0)
{
alph[i][j]=chr[k];
isI=1;
}
else
{
if(chr[k]=='i') chr[k]='i';
if(chr[k]=='j') chr[k]='j';
j--;
}
}
else alph[i][j]=chr[k];
}
else
{
chr[k]='-';
j--;
}
k++;
}
}
chr1--;
k1=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(alph[i][j]=='-')
{
same=0;
chr1++;
for(k1=0;k1<strlen(chr);k1++)
{
if(chr1==chr[k1])
{
same=1; //else same=0;
j--;
break;
}
}
if(same!=1)
{
if(chr1=='i' || chr1=='j')
{
if(isI==0)
{
alph[i][j]=chr1;
isI=1;
}
else j--;
}
else alph[i][j]=chr1;
}
}
}
}
printf("\n\n\n");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
printf("%c ",alph[i][j]);
}
printf("\n");
}
j=0;
for(i=0;i<strlen(chr);i++)
{
if(chr[i]=='-')
{
for(j=i;j<strlen(chr);j++)
{
chr[j]=chr[j+1];
}
}
}
printf("\n\nEnter the plain text : ");
scanf("%s",txt);
j=0;
for(i=0;i<strlen(txt);i++)
{
txt2[j++]=txt[i];
if(txt[i]==txt[i+1])
{
txt2[j++]='x';
}
}
jj=j;
for(i11=0;i11<strlen(txt2);i11+=2)
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(txt2[i11]==alph[i][j])
{
i1=i;
j1=j;
}
if(txt2[i11+1]==alph[i][j])
{
i2=i;
j2=j;
}
}
}
if(i1==i2)
{
if((j1+1)>=5) j1=-1;
if((j2+1)>=5) j2=-1;
//if(j2>j1)
//{
txt2[i11]=alph[i1][j1+1];
txt2[i11+1]=alph[i2][j2+1];
//}
//else
//{
// txt2[i11]=alph[i1][j2+1];
// txt2[i11+1]=alph[i2][j1+1];
//}
}
else if(j1==j2)
{
if((i1+1)>=5) i1=-1;
if((i2+1)>=5) i2=-1;

//if(i1>i2)
//{
// txt2[i11]=alph[i1+1][j1];
// txt2[i11+1]=alph[i2+1][j2];
//}
//else
//{
txt2[i11]=alph[i1+1][j1];
txt2[i11+1]=alph[i2+1][j2];
//}
}
else
{
if(i2>i1)
{
txt2[i11+1]=alph[i2][j1];
txt2[i11]=alph[i1][j2];
}
else
{
txt2[i11]=alph[i2][j1];
txt2[i11+1]=alph[i1][j2];
}
}
}
printf("\nFinal string       : ");
for(i=0;i<jj;i++)
{
printf("%c",txt2[i]);
}
//printf("\nFinal string         : %s",txt2);
getch();
}



/* OUTPUT :

Enter the text : playfair

p l a y f
i r b c d
e g h k m
n o q s t
u v w x z

Enter the plain text : nisargmehtay

Final String : ueyqgoegmqfp 

OUTPUT Sequence :

ni = ue


p l a y f
i r b c d
e g h k m
n o q s t
u v w x z


sa = yq



p l a y f
i r b c d
e g h k m
n o q s t
u v w x z

rg = go


p l a y f
i r b c d
e g h k m
n o q s t
u v w x z

me = eg


p l a y f
i r b c d
e g h k m
n o q s t
u v w x z


ht = mq


p l a y f
i r b c d
e g h k m
n o q s t
u v w x z

ay = fp


p l a y f
i r b c d
e g h k m
n o q s t
u v w x z

Hill Cipher in C

Just paste this program in your Turbo C/C++ compiler...



#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,ans[25][1],sum=0,mtrx[25][25],end;
char txt[25];
clrscr();
printf("\nEnter the string : ");
scanf("%s",txt);
//clrscr();
for(i=0;i<25;i++)
{
if(txt[i]>=97 && txt[i]<122) {}
else
{
end=i;
break;
}
}
for(i=0;i<end;i++)
{
//printf("initial : %d ",txt[i]);
txt[i]=txt[i]-'a';
//printf("final : %d ",txt[i]);
//printf("\n\n");
}
clrscr();
printf("\nEnter matrix...\n");
for(i=0;i<end;i++)
{
for(j=0;j<end;j++)
{
scanf("%d",&mtrx[i][j]);
}
}
for(i=0;i<end;i++)
{
sum=0;
for(j=0;j<end;j++)
{
sum+=mtrx[i][j]*(int)txt[j];
}
ans[i][0]=sum;
}
for(i=0;i<end;i++)
{
printf(" %c",((ans[i][0])%26)+97);
}
getch();
}