Skip to content

Instantly share code, notes, and snippets.

@hakxcore
Last active March 26, 2024 03:12
Show Gist options
  • Save hakxcore/669ce774285e0740b356a5f2d0f2caba to your computer and use it in GitHub Desktop.
Save hakxcore/669ce774285e0740b356a5f2d0f2caba to your computer and use it in GitHub Desktop.
//hakxcore
/* For character stuffing, take two randomly chosen characters
from character set one for FLAG and other for ESCAPE. Assume that chosen
characters are F and E respectively.*/
/* Delimit the input using character F. For every
occurrence of F in data part, stuff E before F. Similarly, for every occurrence
of E in data part stuff E before data E*/
import java.io.*;
import java.util.*;
import java.lang.*;
class Charstuff
{
public static void main(String args[])
{
Scanner k =new Scanner (System.in);
System.out.println("enter the string\t");
String s=k.nextLine();
String str1;
String str2="";
int i,m,j;
m=s.length();
System.out.println("original data "+s);
str1="dlestx";
for(i=0;i<=m-1;i++)
{
if((s.charAt(i)=='d')&&(s.charAt(i+1)=='l')&&(s.charAt(i+2)=='e'))
{
str1=str1+"dle";
}
str1=str1+s.substring(i,i+1);
}
str1=str1+"dleetx";
int p=str1.length();
System.out.println("transmitted data "+str1);
for(i=6;i<p-6;i++)
{
if((str1.charAt(i)=='d')&&(str1.charAt(i+1)=='l')&&(str1.charAt(i+2)=
='e')&&(str1.charAt(i+3)=='d')&&(str1.charAt(i+4)=='l')&&(str1.charAt
(i+5)=='e'))
{
i=i+3;
}
str2=str2+str1.substring(i,i+1);
}
System.out.println("received data is "+str2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment