0
why we added 97 then minus it?
import java.util.*; class multiplicativeCipher{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int shift,i,n; String str; String str1=""; String str2=""; System.out.println("Enter the plain text); str=sc.nextLine(); str=str.toLowerCase(); n=str.length(); char ch1[]=str.toCharArray(); char ch3; char ch4; System.out.println("Enter the key”); shift=sc.nextInt(); System.out.println(); System.out.println("Encrypted text is"); for(i=0;i<n;i++){ if(Character.isLetter(ch1[i])){ ch3=(char)(((int)ch1[i]*shift-97)%26+97); str1=str1+ch3;} else if(ch1[i]==' ' { str1=str1+ch1[i]; } } System.out.println(str1);
1 Antwort
0
I think it is used to find a letter from ASCII table. The first lowercase letter in decimal in the table is 'a' => number 97. Then calculating the current number of the letter in decimal and converting it to char. You can see here the ASCII table http://www.asciitable.com/mobile/.