Java Programming for Caesor Chiper(Encryption)

Encryption 


package lesson1;

import java.util.Scanner;

public class FirstClass {

public static void main(String[] args) {
String plaintext = "ACHYUT";
System.out.println("befor encyption:"+plaintext);
Scanner input = new Scanner(System.in);
System.out.println("enter the key:");
int key = input.nextInt();


System.out.print("After encryption:");
for (int i = 0 ;i < plaintext.length() ;i++)
{
int integervalue = (int)plaintext.charAt(i);
int position = integervalue - 65;
int temp = (position + key)%26;
int backposition = temp + 65;
System.out.print((char)backposition);
}
}

}


OUTPUT:

No comments

Powered by Blogger.