Tuesday, 30 April 2013

CN LAB CRC (16 BIT) PROGRAM


#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j,n,g,a,arr[20],gen[20],b[20],q[20],s;
printf("\n\n\tTransmitter side:");
printf("\n\n\tEnter no. of data bits:");
scanf("%d",&n);
printf("\n\n\tEnter data:");
for(i=0;i< n;i++)
scanf("%d",&arr[i]);
printf("\n\n\tEnter size of generator:");
scanf("%d",&g);
do{
printf("\n\n\tEnter generator:");
for(j=0;j< g;j++)
scanf("%d",&gen[j]);
}
while(gen[0]!=1);
printf("\n\n\tThe generator matrix:");
for(j=0;j< g;j++)
printf("%d",gen[j]);
a=n+(g-1);
printf("\n\n\tThe appended matrix is:");
for(i=0;i< j;++i)
arr[n+i]=0;
for(i=0;i< a;++i)
printf("%d",arr[i]);
for(i=0;i< n;++i)
q[i]= arr[i];
for(i=0;i< n;++i)
{
if(arr[i]==0)
{
for(j=i;j< g+i;++j)
arr[j] = arr[j]^0;
}
else{
arr[i] = arr[i]^gen[0];
arr[i+1]=arr[i+1]^gen[1];
arr[i+2]=arr[i+2]^gen[2];
arr[i+3]=arr[i+3]^gen[3];
}
}
printf("\n\n\tThe CRC is :");
for(i=n;i < a;++i)
printf("%d",arr[i]);
s=n+a;
for(i=n;i< s;i++)
q[i]=arr[i];
printf("\n");
for(i=0;i< a;i++)
printf("%d",q[i]);
}

// EXPECTED OUTPUT :
Transmitter side:
Enter no. of data bits:8
Enter data:1 0 1 0 0 0 0 1
Enter size of generator:4
Enter generator:1 0 0 1

The generator matrix:1001
The appended matrix is:10100001000
The CRC is :111
10100001111
//

Friday, 12 April 2013

JSP PROGRAM TO CALCULATE INCOME TAX, LOGIN AND DATA CAPTURE



CALCULATE INCOMETAX

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Calculate Interest JSP</title>
</head>
<body>
<%
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String gender = request.getParameter("gender");
String profession = request.getParameter("profession");
String prefix = " ";
if (gender.equals("Male")) { prefix = "Mr."; }
else if (gender.equals("Female")) { prefix = "Ms."; } %>
<FONT COLOR = "Blue">Hello <%=prefix %>&nbsp;<%=fname%>&nbsp;<%=lname%> &nbsp; who works in a <%=profession %></FONT>
<% String sincome = request.getParameter("income");
float income = Float.parseFloat(sincome);
out.println("<BR>Your Annual Income is <FONT COLOR = Blue> " +income + "</FONT>");
float tax;
float diff;
if(income <= 100000)
{
out.println("<BR>You are below the Tax Bracket!!");
}
else if(income >100000 && income <= 200000)
{
out.println("<BR>Your Tax Bracket is between Rs.1,00000 to Rs.2,00000");
out.println("<BR><B><U> Tax Rule: </U></B>10% of income above Rs.1 Lakh");
diff = income - 100000;
tax = (float)0.1*diff;
out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+ "</FONT>");
}
else if(income >200000 && income <= 300000)
{
out.println("<BR>Your Tax Bracket is between between Rs.1,00000 to Rs.3,00000");
out.println("<BR><B><U>Tax Rule: </U></B> 10% of income upto Rs.1 Lakh and 20% of rest of income");
diff = income - 200000;
tax = (float)0.2*diff + (float)0.1*100000;
out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+ "</FONT>");
}
else if(income >100000 && income <= 400000)
{
out.println("<BR>Your Tax Bracket is between Rs.1,00000 to Rs.4,00000");
out.println("<BR><B><U>Tax Rule: </U></B>10% of income upto Rs.1 Lakh 20% of income upto Rs.3 Lakh and 30% of rest of income");
diff = income - 300000;
tax = (float)0.3*diff + (float)0.2*200000 + (float)0.1*100000; 
out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax);
}
else if(income > 400000)
{
out.println("<BR>You fall in the tax bracket greater than Rs.4,00000");
diff = income - 400000;
tax = diff + (float)0.3*300000 + (float)0.2*200000 + (float)0.1*100000; 
out.println("<BR><B><U>Tax Rule:</U></B> 10% of income upto Rs.1 Lakh 20% of income upto 3Lakh, 30% of income upto Rs.4 lakh and 100% of rest of income");
out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+ "</FONT>");
}//end if  %>
</body>
</html>



DATA CAPTURE

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import = "java.util.* , java.text.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%!
HashMap hm;
String uname;
String pwd;
Map.Entry entry;
%>
<%
boolean login = false;
hm = new HashMap();
uname = request.getParameter("username");
pwd = request.getParameter("password");
hm.put("Archie","Riverdale");
hm.put("Haddock", "Marlinspike");
hm.put("Hermione","Hogwarts");
Set s = hm.entrySet();
Iterator it = s.iterator();
while(it.hasNext())
{
entry = (Map.Entry) it.next();
if(uname.equals(entry.getKey()) && pwd.equals(entry.getValue()))
{
login=true;
}
}//end while
if(login==true)
{
out.println("<B><FONT COLOR = Blue>");
out.println("Welcome </FONT></B>");
out.println(uname);
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
out.println("<BR><FONT COLOR = Green>");
out.println("Today is </FONT>"+dateFormat.format(date));
%>
<form action="CalculateInterest.jsp" method = "post">
<FONT COLOR = "Magenta"> First Name:</FONT>
<input type = "text" size = "15" name = "fname">
<br>
<FONT COLOR = "Brown">Last Name: </FONT>
<input type = "text" size = "15" name = "lname">
<br>
<FONT COLOR = "Purple">Select your Place of Work:</FONT>
<br>
<select name="profession" size="3">
  <option>IT Company</option>
  <option>Private Bank</option>
  <option>Insurance Company</option>
</select>
<br>
<input type="radio" name="gender" value="Male"> Male<br>
<input type="radio" name="gender" value="Female" checked>Female<br>
<br>
<FONT COLOR = "Red"> Annual Income(in Rupees):</FONT>
<input type = "text" size = "15" name = "income">
<br>
<br>
<input type = "submit" value = "Calculate Tax">
</form>
<%
}
else
{
%>
<jsp:forward page="Login.jsp">
  <jsp:param name="FailReason" value="Wrong Username or Password"/>      
</jsp:forward>
<%
}
%>
</body>
</html>



LOGIN


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Page</title>
</head>
<body>
<form action="dataCapture.jsp" method = "post">
User Name:
<input type = "text" size = "15" name = "username">
<br>
Password:
<input type = "password" size = "15" name = "password">
<br>
<input type = "submit" value = "Login">
</form>
<%
String reason =  request.getParameter("FailReason");
if(reason !=null)
out.println(reason); %>
</body>
</html>









Wednesday, 10 April 2013

CN RSA ALGORITHM PROGRAM IN C


#include<stdio.h>

int phi,M,n,e,d,C,FLAG;
int check()
{
int i;
for(i=3;e%i==0 && phi%i==0;i+2)
{
FLAG = 1;
return;
}
FLAG = 0;
}
void encrypt()
{
int i;
C = 1;
for(i=0;i< e;i++)
C=C*M%n;
C = C%n;
printf("\n\tEncrypted keyword : %d",C);
}
void decrypt()
{
int i;
M = 1;
for(i=0;i< d;i++)
M=M*C%n;
M = M%n;
printf("\n\tDecrypted keyword : %d",M);
}
void main()
{
int p,q,s;

printf("Enter Two Relatively Prime Numbers\t: ");
scanf("%d%d",&p,&q);
n = p*q;
phi=(p-1)*(q-1);
printf("\n\tF(n)\t= %d",phi);
do
{
printf("\n\nEnter e\t: ");
scanf("%d",&e);
check();
}while(FLAG==1);
d = 1;
do
{
s = (d*e)%phi;
d++;
}while(s!=1);
d = d-1;
printf("\n\tPublic Key\t: %d,%d",e,n);
printf("\n\tPrivate Key\t: %d,%d",d,n);
printf("\n\nEnter The Plain Text\t: ");
scanf("%d",&M);
encrypt();
printf("\n\nEnter the Cipher text\t: ");
scanf("%d",&C);
decrypt();
}

INFORMATION


PLEASE FEEL FREE TO ASK ANY DOUBTS ABOUT THE WORKING OF THE PROGRAM.
IF YOU HAVE ANY PROBLEM REGARDING THE EXECUTION OF ANY OF THE PROGRAMS YOU CAN COMMENT ON THE PROGRAM . I'LL DEFINITELY REPLY TO YOUR QUERIES .

REGARDS
SHWETHA (FOUNDER)

JAVA PROGRAMS USING SWINGS PART 2 CONTINUNITY OF THE PREVIOUS SWING PROGRAM



package GUI;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;


public class ProgressBarEg extends JPanel {
static ProgressThread pth; 
static JProgressBar pb;
static JFrame jf; 

public ProgressBarEg() {
setLayout(new BorderLayout()); 
pb = new JProgressBar(); 
JPanel btnpanel = new JPanel();
JButton startbtn = new JButton("Start");
btnpanel.add(startbtn); 
btnpanel.add(pb,"Center");
startbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
startProgressBar(); 
}
}); 
JButton stopbtn = new JButton("Stop");
btnpanel.add(stopbtn); 
    stopbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
stopProgressBar(); 
}
}); 
add(btnpanel);
}//end constructor 
public void startProgressBar() {

if(pth == null || pth.isAlive()) {
pth = new ProgressThread(pb);
pth.start(); 
}
}//end method 
public void stopProgressBar() {
pth.setStop(true); 
}//end method 
public static void main(String a[]){
jf = new JFrame("Copying Files..."); 
ProgressBarEg objpbar = new ProgressBarEg(); 
jf.getContentPane().add("Center", objpbar); 
jf.setSize(200,100); 
jf.addWindowListener(new WindowAdapter() {
public void WindowClosing(WindowEvent we){
System.exit(0); 
}
}); 
jf.setVisible(true); 
}//end main 
}//end ProgressBarEg 

class ProgressThread extends Thread {
JProgressBar pb; 
boolean stopStatus = false; 
boolean aliveStatus = false;
public ProgressThread(JProgressBar pb){
this.pb = pb;
}//end constructor 
public void setStop(boolean value){
stopStatus = value; 
}//end method 
public void run(){
int mini = 0; 
int max = 30; 
pb.setMinimum(mini); 
pb.setMaximum(max); 
for (int x = mini; x<=max; x++){
if(stopStatus){
break; 
}
else {
pb.setValue(x); 
try {
Thread.sleep(100); 
}
catch(InterruptedException ie){
}
}//end else 
}//end for 
aliveStatus=false; 
}//end run method 
}//end class ProgressThread 

JAVA PROGRAMS USING SWINGS PART 1


package GUI;
import javax.swing.*;

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

public class Five extends JPanel implements ActionListener, ItemListener {

String name,hobby,address,citizenship;
static JLabel jl1;

static JMenuBar jmb;
static JMenu jm1;
static JMenuItem jmit1, jmit2, jmit3;
static JTextField jtf;
static JCheckBox jcb;
static JLabel jl2;
static JComboBox jcmb;
static JLabel jl3;
static JTextArea jta;
static JButton jb;
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==jb){
name=jtf.getText();
address=jta.getText();
String tooltip = jb.getToolTipText();
citizenship=jcb.getText();
System.out.println(ae.getActionCommand()+" Was Pressed ");
System.out.println("Name Entered is "+name);
System.out.println(" Address is "+address);
System.out.println(" Citizeship is "+citizenship);
System.out.println(" Tool Tip Text Value for Button is "+tooltip);
}
/*if(ae.getSource()==jcmb){
System.out.println(ae.getActionCommand()+" Was Pressed ");
hobby=(String)jcmb.getSelectedItem();
System.out.println("Hobby Selected is "+hobby);

}*/

}//end actionPerformed

public void itemStateChanged(ItemEvent e){
if(e.getSource() ==jcmb){
if(jcmb.getSelectedItem().equals("Painting")){
System.out.println("Hello Junior MF Hussain!!");
}
else if(jcmb.getSelectedItem().equals("Dancing")){
System.out.println("Hello Junior Vani Ganapathi!!");
}
else if(jcmb.getSelectedItem().equals("Singing")){
System.out.println("Hello Junior Asha Bhosle!!");
}
}
}

public static void main(String a[]){
Five objfive = new Five();
JFrame jf = new JFrame("Frame");
JPanel jp = new JPanel();
jf.add(jp);
jl1 = new JLabel("Enter Your Name");
jtf = new JTextField(15);
jcb = new JCheckBox("Indian Citizen",true);
jl2 = new JLabel("Choose Your Hobby");
jcmb = new JComboBox();
jcmb.addItem("Painting");
jcmb.addItem("Dancing");
jcmb.addItem("Singing");
jcmb.addItem("Trekking");
jl3 = new JLabel("Enter Your Address");
jta = new JTextArea(20,20);
jb = new JButton("Click Me");
jb.setBounds(20,20,120,120);
jb.setToolTipText("Submit Values...See Console");
jmb = new JMenuBar();
jm1 = new JMenu("File");
jm1.setMnemonic(KeyEvent.VK_F);
jmit1 = new JMenuItem("Open");
jmit1.setMnemonic(KeyEvent.VK_O);
        jmit2 = new JMenuItem("Save");
        jmit2.setMnemonic(KeyEvent.VK_S);
        jmit3 = new JMenuItem("Exit");
        jmit3.setMnemonic(KeyEvent.VK_X);
        jmit3.setToolTipText("Exit application");
        jm1.add(jmit1);
        jm1.add(jmit2);
        jm1.add(jmit3);
        jmb.add(jm1);
        //setJMenuBar(jmb);
        jf.setTitle("Simple menu");
jp.add(jl1);
jp.add(jtf);
jp.add(jcb);
jp.add(jl2);
jp.add(jcmb);
jp.add(jl3);
jp.add(jta);
jb.addActionListener(objfive);
//jcmb.addActionListener(objfive);
jcmb.addItemListener(objfive);
jp.add(jb);
//jf.add(jmb);
jf.setSize(400,400);
jf.setVisible(true);
}//end main
}//end class Five