In: Computer Science
write a java program to Translate or Encrypt the given string :
(input char is all in capital letters) { 15 }
*) Each character replaced by new character based on its position
value in english alphabet. As A is position is 1, and Z is position
26.
*) New characters will be formed after skipping the N (position
value MOD 10) char forward. A->A+1= B , B->B+2=D
,C->C+3=F, .... Y->Y+(25%10)->Y+5=D
A B C D E F G H I J K l M N O P Q R S T U V W X Y Z
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
26
Input : AFGKJX
Outout: BLNLJB
import java.util.Scanner;
class Encrypt
{
public static void main(String[] args)
{
String
alphabets="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Scanner input=new Scanner(System.in);
System.out.print("Enter text to encrypt:
");
String text=input.next();
String output="";
int pos;
//encrypt the given data
for(int i=0;i<text.length();++i)
{
pos=(alphabets.indexOf(text.charAt(i)));
pos=((pos+1)%26+(pos+1)%10);
if(pos>26)
pos=pos-26;
output=output+alphabets.charAt(pos-1);
}
System.out.println("Encrypted text: "+output);
}
}
Output