sajjads programming blog

publish my programming stuffs on web

Sunday, August 13, 2006

caeser cypher java applet

################ created by sajjad##########################################
import java .applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class caeser extends Applet implements ActionListener
{
TextField plain,cypher;
Button enc, dec,flp,flc;
Label l1,l2,l3;
String str1,str2;

char ch[]=new char[100];
//={'a','s','b','s','d','r','e','d','w','3','4'};

public void init() {
setLayout(new FlowLayout(4));
setBackground(Color.ORANGE);
l3= new Label("caeser cypher ");
add(l3);
l1= new Label("plain text");
add(l1);
plain= new TextField("Enter plain text", 20);
add(plain);
enc= new Button("encrypt");
add(enc);
enc.addActionListener(this);

dec= new Button("decrypt");
add(dec);
dec.addActionListener(this);

flp=new Button("Flush plain");
add(flp);
flp.addActionListener(this);

flc=new Button("Flush cypher");
add(flc);
flc.addActionListener(this);

l2= new Label("cypher text");
add(l2);
cypher= new TextField("decrypted text",20);
add(cypher);


// TODO start asynchronous download of heavy resources
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==enc)
{
str1= new String(plain.getText());
for(int i=0;i {
ch[i]=str1.charAt(i);
for(int j=0;j<5;j++)
ch[i]++ ;
}
String str2= new String(ch,0,str1.length());
cypher.setText(str2);
}
if(e.getSource()==dec)
{
str1= new String(cypher.getText());
for(int i=0;i {
ch[i]=str1.charAt(i);
for(int j=0;j<5;j++)
ch[i]-- ;
}
String str2= new String(ch,0,str1.length());
plain.setText(str2);
}
if(e.getSource()==flp)
plain.setText("");

if(e.getSource()==flc)
cypher.setText("");
}
}

Wednesday, August 09, 2006

refractive_new.py





import pygame
import math
import pygame.font
from pygame.locals import *
color=(255,255,255)
u=0
sin_i=0
sin_r=0
r_index=1.33
emitter_y=20
value=200

deviation=0
screen=pygame.display.set_mode((1000,700))

river=pygame.image.load("scaled_river.jpeg")
def colorchooser():
pygame.draw.rect(screen,(255,255,255),(20,20,20,20),0)
pygame.draw.rect(screen,(255,0,0),(20,60,20,20),0)
pygame.draw.rect(screen,(0,255,0),(20,100,20,20),0)
pygame.draw.rect(screen,(0,0,255),(20,140,20,20),0)
def prntrindex():
string='n2='+str(r_index)
text_d1 = font.render(string,1, (255,255,255))
textpos_d1 = ((900,80,48,24))
screen.blit(text_d1,textpos_d1)
def pgbar():
pygame.draw.line(screen,(255,255,0),(950,200),(950,300),5)
pygame.draw.polygon(screen,(255,255,0),((940,175),(960,175),(950,190)) ,0)
pygame.draw.polygon(screen,(255,255,0),((940,325),(960,325),(950,310)) ,0)

i=200
while i<=300: if value==i: pygame.draw.line(screen,(255,255,0),(940,i),(960,i),5) else: pygame.draw.line(screen,(255,255,0),(940,i),(960,i),2) i+=20 def inc_angle(): opposite_side=400 dx=400 dy=400-emitter_y #hypt=pow((pow(dx,2)+pow(dy,2)),.5) hypt=math.sqrt(dx*dx +dy*dy) sin_i=opposite_side/hypt degr=math.degrees(math.asin(sin_i)) # opposite side=(100,emitter_y)-(100,400) #print incident angle string='i='+str(int(degr)) text_d1 = font.render(string,1, (255,255,255)) textpos_d1 = ((900,20,48,24)) screen.blit(text_d1,textpos_d1) return sin_i def emitter(): inci=inc_angle() sin_r=inci/r_index refr=math.degrees(math.asin(sin_r)) # print refracted angle string2='r='+str(int(refr)) text_r = font.render(string2,1, (255,255,255)) textpos_r = ((900,50,48,24)) screen.blit(text_r,textpos_r) # evaluating x for drawing cos_r=math.cos(math.asin(sin_r)) refracted_x= math.sqrt(pow(300/cos_r,2)-(300*300))+500 if color==(255,0,0): deviation=40 elif color==(0,255,0): deviation=20 elif color==(0,0,255): deviation=0 if color==(255,255,255): pygame.draw.line(screen,(255,0,0),(500,400),(refracted_x+40,700),1) pygame.draw.line(screen,(0,255,0),(500,400),(refracted_x+20,700),1) pygame.draw.line(screen,(0,0,255),(500,400),(refracted_x,700),1) else: pygame.draw.line(screen,color,(500,400),(refracted_x+deviation,700),1) def refra(): screen.fill((0,0,0)) screen.blit(river,(0,400)) #emitter position selecter pygame.draw.rect(screen,(255,255,0),(100,20,3,285),0) #emitter line pygame.draw.line(screen,color,(100,emitter_y),(500,400),2) #normal pygame.draw.line(screen,(255,255,255),(500,0),(500,700),1) #refracted line emitter() pgbar() pygame.init() font=pygame.font.Font(None,25) while 1: event=pygame.event.wait() if event.type is MOUSEBUTTONDOWN: x,y=pygame.mouse.get_pos() #print 'x=', x, 'y=',y if x> 95 and x<105>20 and y<305: emitter_y="y">20 and x<40:>20 and y<40: color="(255,255,255)">60 and y<80: color="(255,0,0)">100 and y<120: color="(0,255,0)">140 and y<160: color="(0,0,255)">940 and x<960>175 and y<190:>2:
r_index=2
if value>300:
value=300
elif x>940 and x<960>310 and y<325:
value-=20
r_index-=.2
if r_index<1:
r_index=1
if value<200:
value=200


refra()
prntrindex()
colorchooser()
pygame.display.update()

Tuesday, August 08, 2006

linuxgallery

linuxgallery

refractive index


# this program is developed under space (www.space_kerala.org) project # developed by sajjad( csajjad@gmail.com) , vibeesh(pvibeesh@gmail.com) George john #

import pygame
import math
import pygame.font
from pygame.locals import *
u=0
r_index=1.33
emitter_y=20
value=200
color=(255,255,255)
deviation=0
screen=pygame.display.set_mode((700,610))

river=pygame.image.load("river.jpeg")
def colorchooser():
pygame.draw.rect(screen,(255,255,255),(20,20,20,20),0)
pygame.draw.rect(screen,(255,0,0),(20,60,20,20),0)
pygame.draw.rect(screen,(0,255,0),(20,100,20,20),0)
pygame.draw.rect(screen,(0,0,255),(20,140,20,20),0)
def prntrindex():
string='n2='+str(r_index)
text_d1 = font.render(string,1, (255,255,255))
textpos_d1 = ((600,80,48,24))
screen.blit(text_d1,textpos_d1)
def pgbar():
pygame.draw.line(screen,(255,255,0),(650,200),(650,300),5)
pygame.draw.polygon(screen,(255,255,0),((640,175),(660,175),(650,190)) ,0)
pygame.draw.polygon(screen,(255,255,0),((640,325),(660,325),(650,310)) ,0)

i=200
while i<=300: if value==i: pygame.draw.line(screen,(255,255,0),(640,i),(660,i),5) else: pygame.draw.line(screen,(255,255,0),(640,i),(660,i),2) i+=20 def inc_angle(): opposite_side=250 dx=250 dy=400-emitter_y #hypt=sqrt(pow(dx,2)+pow(dy,2)) hypt=pow((pow(dx,2)+pow(dy,2)),.5) angle=math.asin(opposite_side/hypt) degr=math.degrees(angle) string='i='+str(int(degr)) text_d1 = font.render(string,1, (255,255,255)) textpos_d1 = ((600,20,48,24)) screen.blit(text_d1,textpos_d1) return degr def emitter(): inci=inc_angle() refr=inci/r_index string2='r='+str(int(refr)) text_r = font.render(string2,1, (255,255,255)) textpos_r = ((600,50,48,24)) screen.blit(text_r,textpos_r) angle=90-refr rad_angle=math.radians(angle) hyp=210/math.sin(rad_angle) val=pow(hyp,2)-pow(210,2) if color==(255,0,0): deviation=40 elif color==(0,255,0): deviation=20 elif color==(0,0,255): deviation=0 refracted_x=math.sqrt(val) #+350 refracted_x=refracted_x+350 if color==(255,255,255): pygame.draw.line(screen,(255,0,0),(350,400),(refracted_x+40,610),1) pygame.draw.line(screen,(0,255,0),(350,400),(refracted_x+20,610),1) pygame.draw.line(screen,(0,0,255),(350,400),(refracted_x,610),1) else: pygame.draw.line(screen,color,(350,400),(refracted_x+deviation,610),1) def refra(): #x=450-u x=450 if x<380: x="350" font="pygame.font.Font(None,25)" event="pygame.event.wait()" y="pygame.mouse.get_pos()" x="'," y="',y"> 95 and x<105>20 and y<205: emitter_y="y">20 and x<40:>20 and y<40: color="(255,255,255)">60 and y<80: color="(255,0,0)">100 and y<120: color="(0,255,0)">140 and y<160: color="(0,0,255)">640 and x<660>175 and y<190:>2:
r_index=2
if value>300:
value=300
elif x>640 and x<660>310 and y<325:
value-=20
r_index-=.2
if r_index<1:
r_index=1
if value<200:
value=200
#if event.type is KEYDOWN :
#if event.key==K_k:
#u+=20
#elif event.key==K_f:
#u-=20

refra()
prntrindex()
colorchooser()
pygame.display.update()


##################################################