postheadericon Transposition cipher example using Java

Write a programs to simulate encryption and decryption technique using Transposition (Columnar) Cipher, algorithm development and Communication between client and server will be done using Java server socket programming.

TranspositionCipher.java

package bsr;
import java.util.*;
import java.net.*;
import java.io.*;
/*A code from www.bipinrupadiya.com*/
public class TranspositionCipher
{
public String selectedKey;
public char sortedKey[];
public int  sortedKeyPos[];

postheadericon Mono-alphabetic Substitution Cipher example using Java

Write a programs to simulate encryption and decryption technique using Mono-alphabetic Substitution Cipher, algorithm development and Communication between client and server will be done using Java server socket programming.

MonoAlphabeticSubstitutionCipher.java

package bsr;
import java.util.*;
import java.net.*;
import java.io.*;
/*A code from www.bipinrupadiya.com*/
public class MonoAlphabeticSubstitutionCipher
{
public char p[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
public char ch[] = {'Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M'};
public String doEncryption(String s)
{

postheadericon Generalized Caesar Cipher example using java

Write a programs to simulate encryption and decryption using Caesar Cipher. algorithm development and Communication between client and server is done using Java socket programming.


CaesarCipher.java

package bsr;
import java.util.*;
import java.net.*;
import java.io.*;
/*A code from www.bipinrupadiya.com*/
public class CaesarCipher
{
char a[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int key=3;

postheadericon java socket programming example



In the era of network programming means write such a script that can be executed on multiple computers / platform. In J2SE, a package java.net provide the number of API that can be used to write code for the communication between multiple computers / platforms. The java.net package of J2SE provide the sport for two important protocol of the network that is TCP and UDP.

The Socket in java provide the way of communication between two or more computers using Transmission Control Protocol (TCP). Here we have  socket  on both side at Client as well as server. A client socket try to communicate to server socket. If everything is fine server accept the connection and communication process begin.

Here I am going to demonstrate a simple example of server socket programming. I have created a java package  bsr and my class that have the definition of socket MySocket.java is placed inside this package. 

I have also created two more class to simulate the behavior of client and server namely sender and  receiver. I used plain text editor to create my script.


postheadericon Protocol 3 A Simplex Protocol for a Noisy Channel

header.h


#include<stdio.h>
#include<fcntl.h>
#include<string.h>
//define Frame structure
struct frame
{
int frame_type;//{1-frame, 0-ack}
int seqno;
int ackno;
char data[50];
};
//services used @ sender side
void from_network_layer(char buffer[])
{
printf("\nEnter Data : ");
scanf("%s",buffer);
}
void to_physical_layer(struct frame *f)
{
int pid1;
system(">pipe1");
pid1=open("pipe1",O_WRONLY);
write(pid1,f,sizeof(struct frame));
close(pid1);
if(f->frame_type==1)
{
printf("\n\n\tFrame [%d]-[%s] sucessfully send.\n",f->seqno,f->data);
}
else
{
printf("\n\n\tAcknowledment [%d]-[%s] sucessfully send.\n",f->ackno,f->data);
}
}
int get_ack()
{
int pid2,ackno=0;
pid2=open("pipe2",O_RDONLY);
if(pid2>0)
{
read(pid2,&ackno,sizeof(ackno));
unlink("pipe2");
}
close(pid2);
return ackno;
}
int start_timer(int seqno)
{
printf("\nTimer Starts");
int i=1,flag=1;
for(i=1;i<=10;i++)
{
sleep(1);
if(seqno==get_ack())
{
flag=0;
break;
}
printf("\ntime : %d ",i);
}
return flag;
}
//services used @ reciving side
void from_physical_layer(struct frame *f)
{
int pid1;
pid1=open("pipe1",O_RDONLY);
f->seqno=0;
if(pid1>0)
{
read(pid1,f,sizeof(struct frame));
unlink("pipe1");
}
close(pid1);
}

void to_network_layer(struct frame *f)
{

printf("\n\nframe No [ %d ]-[%s]received successfully\n",f->seqno,f->data);

}
void send_ack(int seqno)
{
int pid2;
system(">pipe2");
pid2=open("pipe2",O_WRONLY);
if(pid2>0)
{
write(pid2,&seqno,sizeof(seqno));
}
close(pid2);
}

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.