Sunday, 18 October 2015


PRACTICAL NO-1(a)

Aim: Write a program to implement Caesar Cipher Substitution Technique.

Program:

import java.*;
import java.util.*;
import java.lang.String;
class cs
{
public static void main(String[] args)throws Exception
{
try
{
int key;

String s;

Scanner in = new Scanner(System.in);
System.out.println("Enter a string to encrypt");
     
              s = in.nextLine();
              char arr[]=s.toCharArray();
             
              String str=" ";
              for (int i=0;i < s.length(); i++)
              {
             
              int helper=s.charAt(i);
      helper=(helper+3);

      if (helper>'Z'||helper>'z') helper =(helper-26);
      if (helper<'A'||helper<'a') helper=(helper+26);

      str= str+(char)helper;
    }
            System.out.println("Ciphrt text: "+ str);
            }
            catch(Exception e)
            {
            System.out.println("Error"+e);
           
            }
            }
            }



Output:

Enter a string to Encrypt : hello

Cipher Text : khoor 















No comments:

Post a Comment