0% found this document useful (0 votes)
34 views3 pages

Assignment No 5

Uploaded by

Shubham waghule
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

Assignment No 5

Uploaded by

Shubham waghule
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment No.

5
Write a program to implement Caesar Cipher

import java.util.*;
class CeaserCipher
{
//Encrypts text using a shift od s
public static StringBuffer encrypt(String text,int s)
{
StringBuffer result=new StringBuffer();
for(int i=0;i<text.length();i++)
{
if(Character.isUpperCase(text.charAt(i)))
{
char ch=(char)(((int)text.charAt(i)+s-65)%26+65);
result.append(ch);
}
else
{
char ch=(char)(((int)text.charAt(i)+s-97)%26+97);
result.append(ch);
}
}
return result;
}
//Driver code
public static void main(String[]args)
{
String text;
System.out.println("Enter Text Here=");
Scanner sc=new Scanner(System.in);
text=sc.next();
int s=3;
System.out.println("Text :"+text);
System.out.println("Shift :"+s);
System.out.println("Cipher :"+encrypt(text,s));
}
}

Output :

You might also like