Follow me on Linkedin

Encrypt & Decrypting Messages

 /*
Exercise : Ex 3
Title : Sender Program..
Author :Aslam Jainul
*/

import java.io.*;
import java.net.*;
import java.util.*;
 class sender
{
public static void main(String args[])
{
try
{
int key;
DataInputStream dis=new DataInputStream(System.in);

key=2;
System.out.println("enter the name");
String f=dis.readLine();
File f1=new File(f);
FileReader fr=new FileReader(f1);
Socket s=new Socket("192.168.208.118",8081);
PrintWriter put=new PrintWriter(s.getOutputStream(),true);
put.println(f);
int c=0;
while((c=fr.read())!= -1)
{
put.println(c+key);
}
System.out.println("File content transferred");
fr.close();
s.close();
}
catch(Exception e)
{}
}
}


 /*
Exercise : Ex 3
Title : Receiver Program..
Author :Aslam Jainul
*/

import java.io.*;
import java.net.*;
import java.util.*;
 class receiver
{
public static void main(String args[]) throws IOException
{
ServerSocket ss;
Socket s;
try
{
System.out.println("waiting for client");
ss=new ServerSocket(8081);
s=ss.accept();
System.out.println("connection established");
BufferedReader get=new BufferedReader(new InputStreamReader(s.getInputStream()));
String fname;
fname=get.readLine();
fname="TR_"+fname;
System.out.println("file name is:"+fname);
File f=new File(fname);
FileWriter fw=new FileWriter(f);
String c;
while((c=get.readLine())!=null)

fw.write(Integer.parseInt(c));
System.out.println("received content stored");
fw.close();
s.close();
}
catch(Exception e)
{}
}
}

 /*
Exercise : Ex 3
Title : Decrypt File
Author :Aslam Jainul
*/

import java.io.*;
import java.net.*;
import java.util.*;
 class decript
{
public static void main(String args[])
{
try
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter the encrypted file name with extension");
String fname=dis.readLine();
File f1=new File(fname);
FileReader fr=new FileReader(f1);
File f2=new File("dec_"+fname);
FileWriter fw=new FileWriter(f2);
int c=0;
while((c=fr.read())!=-1)
{
System.out.println(c-2);
fw.write(c-2);
}
fr.close();
fw.close();
}
catch(Exception e)
{}
}
}




UDP Receiver & Sender Program

 /*
Exercise : Ex 2(b)
Title : UDP Receiver Program..
Author :Aslam Jainul
*/
 import java.io.*;
                 import java.net.*;
                 import java.util.*;
                 public class UdpReceiver
                 {
                     public static void main(String args[])throws IOException
                     {
                          try
                             {
                                 DataInputStream dis=new DataInputStream(System.in);                              
                                 byte[] rdata=new byte[1024];
                                                        
                       
                               DatagramSocket s=new DatagramSocket(9876);
                               DatagramPacket rpack=new DatagramPacket(rdata,rdata.length);
                           
                               System.out.println("Waiting for file name:");
                               s.receive(rpack);
                           
                               String fname=new String(rpack.getData());
                               System.out.println("From server : "+fname);
                                                     
                             fname="TR_"+fname;
                             System.out.println("File name is : "+fname);
                         
                             File f=new File(fname);
                             FileWriter fw=new FileWriter(f);
                         
                           
                             while(true)
                             {
                             
                             byte[] rdata1=new byte[1024];                           
                             DatagramPacket rpack1=new DatagramPacket(rdata1,rdata1.length);
                           
                             s.receive(rpack1);
                             String txt=new String(rpack1.getData());
                             fw.write(txt);
                             System.out.print(txt);
                             if(txt.trim().equals("done"))
                             {
                                  System.out.println("Process finished");
                                  fw.close();
                                  break;
                             }
                             
                             }
                         }
                         catch(IOException e)
                         {          System.out.println(""+e);
                         }
                     }
                 }


 /*
Exercise : Ex 2(b)
Title : UDP Sender Program..
Author :Aslam Jainul
*/
   import java.io.*;
                   import java.net.*;
                   import java.util.*;
                   public class UdpSender
                   {
                        public static void main(String args[])
                        {
                             try
                             {
                                  DataInputStream dis=new DataInputStream(System.in);
                                  System.out.println("Enter the file name :");
                                  String f=dis.readLine();

                               
 byte[] sdata=new byte[1024];                           
                             sdata=f.getBytes();
                               
                               InetAddress ipa=InetAddress.getByName("127.0.0.1");
                               DatagramSocket s=new DatagramSocket();
                               DatagramPacket spack=new DatagramPacket(sdata,sdata.length,ipa,9876);
                               s.send(spack);
                             
                                  File f1= new File(f);
                                  FileReader fr=new FileReader(f1);
                                  int n=0;
                                  byte[] buffer=new byte[1024];
                             
StringBuffer fileData = new StringBuffer(1000);
        BufferedReader reader = new BufferedReader(new FileReader(f));
        char[] buf = new char[1024];
        int numRead=0;
        while((numRead=reader.read(buf)) != -1)
        {
            String readData = String.valueOf(buf, 0, numRead);
            System.out.print(readData);
            buffer=readData.getBytes();
        DatagramPacket spack1=new DatagramPacket(buffer,buffer.length,ipa,9876);
           s.send(spack1);
        }                            
                             
byte[] endChar=new byte[1024];
endChar="done".getBytes();
spack=new DatagramPacket(endChar,endChar.length,ipa,9876);
s.send(spack);
         }
         catch(IOException e)
         {
          System.out.println(""+e);
         }
    }
}



TCP Receiver & Sender Program

/*
Exercise : Ex 2(a)
Title : TCP Receiver Program..
Author :Aslam Jainul
*/

import java.io.*;
import java.net.*;
import java.util.*;
public class TCPreceiver
{
public static void main(String args[])
{

ServerSocket ss;
Socket s;
try
{
System.out.println("Waiting for Client........");
ss=new ServerSocket(8081);
s=ss.accept();
System.out.println("Connection Done...!!");
BufferedReader get=new BufferedReader(new InputStreamReader(s.getInputStream()));
String fname;
System.out.println("From : " + s.getInetAddress() );

fname=get.readLine();
fname="TR_" +fname;
System.out.println("file name is:" +fname);
File f=new File(fname);
FileWriter fw=new FileWriter(f);
String c;
while((c=get.readLine())!=null)
fw.write(Integer.parseInt(c));
System.out.println("Contents Received..");
fw.close();
s.close();
}
catch(Exception e)
{}

}
}


/*
Exercise : Ex 2(a)
Title : TCP Sender Program..
Author :Aslam Jainul
*/

import java.io.*;
import java.net.*;
import java.util.*;
public class TCPsender
{
public static void main(String args[])
{
try
{
System.out.println("Enter the File Name you wanna transfer ...");
DataInputStream dis=new DataInputStream(System.in);
String f=dis.readLine();
File f1=new File(f);
FileReader fr=new FileReader(f1);
Socket s=new Socket("192.168.208.118",8081);
PrintWriter put=new PrintWriter(s.getOutputStream(),true);
put.println(f);
int c=0;
while((c=fr.read())!=-1)
put.println(c);
System.out.println("File Transfered....");
fr.close();
s.close();
}
catch(Exception e)
{}
}
}




Program for using Ping command

/*
Exercise : Ex 1(b)
Title : Program for using ping command..
Author :Aslam Jainul
*/

import java.net.*;
import java.io.*;
import java.net.InetAddress.*;
public class EX_1_B_Ping
{
public static void main(String args[])
{
try
{
DataInputStream obj= new DataInputStream(System.in);

System.out.println("Enter the IP/Name Address.....");

String user_str = obj.readLine();

String mystring ="ping " + user_str ;

Runtime r= Runtime.getRuntime();
Process p=r.exec(mystring);

DataInputStream obj1= new DataInputStream(p.getInputStream());

String  data=obj1.readLine();
while(data !=null )
{
System.out.println(data);
data=obj1.readLine();
}
}

catch(Exception E)
{
System.out.print("SOME ERROR OCCURED");
}
}
}

Output :


Program to find IP address of a computer

/*
Exercise : Ex 1(a)
Title : Program to find IP Address of a computer..
Author :Aslam Jainul
*/

import java.net.*;
import java.io.*;
import java.net.InetAddress.*;
public class EX_1_A_IP
{
public static void main(String args[])
{
try
{
DataInputStream obj= new DataInputStream(System.in);

System.out.println("Enter the IP Address.....");

String user_str = obj.readLine();

System.out.println();
InetAddress ip =InetAddress.getByName(user_str);
if(ip.isReachable(3000))
{

System.out.print(" The given IP address is ACTIVE");
System.out.print(" \n\n");
System.out.print(" Host Name : ");
System.out.print(ip.getHostName());
System.out.print(" \n\n");
System.out.print(" Host Address : ");
System.out.print(ip.getHostAddress());
System.out.print(" \n\n");

}
else
{
System.out.println("The given IP address is INACTIVE");
}
}

catch(Exception E)
{
System.out.print("SOME ERROR OCCURED");
}
}
}

Output :





The program can't start because libgcc_s_dw2-1.dll is missing from your computer. Try reinstalling the program to fix this problem.







Download the file and install it & Restart your system. 



Tag : How to fix the dll error ? The program can't start because libgcc_s_dw2-1.dll is missing from your computer.  Try reinstalling the program to fix this problem .  libgcc_s_dw2-1.dll file is missing . download  libgcc_s_dw2-1.dll is missing ,  libgcc_s_dw2-1.dll is missing error , how to download  libgcc_s_dw2-1.dll is missing . error in dll , The program can't start because libgcc_s_dw2-1.dll is missing from your computer.  Try reinstalling the program to fix this problem , The program can't start because libgcc_s_dw2-1.dll is missing from your computer.  Try reinstalling the program to fix this problem. The program can't start because libgcc_s_dw2-1.dll is missing from your computer.  Try reinstalling the program to fix this problem , notepad++ , notepad , eclipse .

Cyclic Nature

Cyclic nature of data type in C:

In C some data types shows one special properties that when we 
assign a value beyond range of that data type then it will not any 
compiler error but assign a number according to some cyclic order. 
This property is known as cyclic nature of data type.
Data type which shows cyclic nature:
(a) char
(b) int
(c) long int
Data type which doesn't show cyclic nature:
(a) float
(b) double
(c) long double

1. Cyclic nature of unsigned char:
Range of unsigned char is 0 to 255. 
If we will assign a value greater than  255 then value of variable will be 
changed to a value if we will move clockwise direction 
as shown in the figure according to number. 
If number is less than 0 then move in anti clockwise direction.


Short cut formula to find cyclic value:
If number is X where X is greater than 255 then
New value = X % 256
If number is Y where Y is less than 0 then
New value = 256 – (Y% 256)


2. Cyclic nature of signed
 char:

Range of unsigned char is -128 to 127. 
If we will assign a value greater than 127 then value of variable will be 
changed to a value if we will move clockwise direction 
as shown in the figure according to number. 
If number is less than -128 then move in anti clockwise direction.



Short cut formula to find cyclic value:
If number is X where X is greater than 127 then
p = X % 256
if p <=127 
New value = p 
else 
New value = p – 256
If number is Y where Y is less than -128 then
p = Y % 256 
If p <= 127 
New value = -p 
else 
New value = 256 -p

3. Cyclic nature of unsigned int:

Range of unsigned int is 0 to 653535. 
If we will assign a value greater than 65535 then value of variable will be 
changed to a value if we will move clockwise direction 
as shown in the figure according to number. 
If number is less than 0 then move in anti clockwise direction.
Short cut formula to find cyclic value:
If number is X where X is greater than 65535 then
New value = X % 65536
If number is Y where Y is less than 0 then
New value = 65536– (Y% 65536)


4. Cyclic nature of signed int:

Range of unsigned int is -32768 to 32767. 
If we will assign a value greater than 32767 then value of variable will be 
changed to a value if we will move clockwise direction 
as shown in the figure according to number. 
If number is less than -32768 then move in anti clockwise direction.
If number is X where X is greater than 32767 then
p = X % 65536
if p <=32767 

New value = p 
else 
New value = p - 65536 
If number is Y where Y is less than -32768 then 
p = Y % 65536 
If p <= 32767 
New value = -p 
else 
New value = 65536 -p 



Note: Same rule is also applicable in case of signed long int and 
unsigned long int.








a