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

Experiment:01: Aim:-Program

The document describes a Java program that implements the Caesar cipher technique to encrypt and decrypt plaintext. The program prompts the user to enter plaintext and an encryption key. It then uses the key to encrypt the plaintext into ciphertext by shifting each letter by the key amount. The program also decrypts the ciphertext back into the original plaintext using the same key.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Experiment:01: Aim:-Program

The document describes a Java program that implements the Caesar cipher technique to encrypt and decrypt plaintext. The program prompts the user to enter plaintext and an encryption key. It then uses the key to encrypt the plaintext into ciphertext by shifting each letter by the key amount. The program also decrypts the ciphertext back into the original plaintext using the same key.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT :01

Aim:-Write a JAVA program to implement Caesar cipher Technique.

PROGRAM:
import java.io.BufferedReader;

import java.io.InputStreamReader;

public class CaesarCipher

public static void main(String args[])throws Exception

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("enter the plain text");

String pt=br.readLine();

String ct;

System.out.println("enter the key value:");

int key=Integer.parseInt(br.readLine());

ct=doEncrypt(pt,key);

System.out.println("encrypted plain text is:");

System.out.println(ct);

pt=doDecrypt(ct,key);

System.out.println("decrypted cipher text is:");

System.out.println(pt);

static String doEncrypt(String pt,int key)

{
char c;

int num;

StringBuffer sb=new StringBuffer(pt);

for(int i=0;i<sb.length();i++)

num=sb.charAt(i)-65;

num=num+key;

if(num>=26)

num=num-26;

c=(char)(num+65);

sb.setCharAt(i,c);

return new String(sb);

static String doDecrypt(String ct,int key)

return doEncrypt(ct,26-key);

}
OUTPUT:

You might also like