Source Codes > Network Security Algorithms > Monoalphabetic
Monoalphabetic
//Monoalphabetic
import java.io.*;
class Onec
{
public static void main(String args[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String accept="",result=""; int a=0,i,j,k=0;
char code[]={'d','g','h','r','a','k','i','l','p','j','z','s','b','t','m','q','w','u','x','n','c','f','o','u','e','v'};
char alpha[]=new char[100];
System.out.println("Enter you plain text");
accept=br.readLine();
for(k=0;k<26;k++)
{
a=97+k;
alpha[k]=(char)a;
//System.out.print(alpha[k]+" ");
}
String cipher="";
for(i=0;i<accept.length();i++)
{
char temp=accept.charAt(i);
if(temp==' ')
{ cipher+=" "; continue;}
for(j=0;j<26;j++)
{
if(temp==alpha[j])
{ cipher+=code[j]; }
else
{}
}
}
System.out.println("\nCipher text is "+cipher);
//Decrypt
//System.out.println("\nDecryption");
}
}
import java.io.*;
class Onec
{
public static void main(String args[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String accept="",result=""; int a=0,i,j,k=0;
char code[]={'d','g','h','r','a','k','i','l','p','j','z','s','b','t','m','q','w','u','x','n','c','f','o','u','e','v'};
char alpha[]=new char[100];
System.out.println("Enter you plain text");
accept=br.readLine();
for(k=0;k<26;k++)
{
a=97+k;
alpha[k]=(char)a;
//System.out.print(alpha[k]+" ");
}
String cipher="";
for(i=0;i<accept.length();i++)
{
char temp=accept.charAt(i);
if(temp==' ')
{ cipher+=" "; continue;}
for(j=0;j<26;j++)
{
if(temp==alpha[j])
{ cipher+=code[j]; }
else
{}
}
}
System.out.println("\nCipher text is "+cipher);
//Decrypt
//System.out.println("\nDecryption");
}
}