Friday, November 20, 2020

#497 Write a code java to do caesar's code is

Write a code java to do caesar's code is - Computer Science

ChemistryExplain daily providing Q&A content “#497 Write a code java to do caesar's code is" in Computer science, Ba computer science, Berkeley computer science, a Computer science associate degree jobs

ChemistryExplain “#497 Write a code java to do caesar's code is in Computer science, Ba computer science, Berkeley computer science
Get the Free Online Chemistry Q&A Questions And Answers with explain. To crack any examinations and Interview tests these Chemistry Questions And Answers are very useful. Here we have uploaded the Free Online Chemistry Questions. Here we are also given the all chemistry topic.

 ChemistryExplain team has covered all Topics related to inorganic, organic, physical chemistry, and others So, Prepare these Chemistry Questions and Answers with Explanation Pdf.

For More Chegg Questions

Join Our Telegram Channel for Covers All Update by ChemistryExplain:- Click Now

Free Chegg Question

write a code java to do
Caesar's Code is a basic encryption algorithm. It is a
substitution cipher where each letter is replaced with another
letter of a fixed position (the difference between the two
letters is a fixed offset). For example, if the plaintext word is
(Abc) and the offset is 3, then the ciphertext is (Def).
Caesar's algorithm is a simple encryption technique. You are
required to implement a modified version of the algorithm
described as follows:
- Convert capital letters into small letters and vice versa.
- Use two offsets (n1 and n2) to encrypt the letters of
plaintext alternatively. Those offsets should be strictly positive
and greater than 1.
- keep digits and symbols unchanged.
Implement an encryption algorithm and ask the user to enter
a plaintext and valid two integers (ni and n2). Then print the
ciphered text.
You can use the console or dialogs as an application's
interface.

Free Chegg AnswerFor More Chemistry Notes and Helpful Content Subscribe Our YouTube Chanel - Chemistry Explain  

Free Chegg Answer

import java.util.*;
public class Main
{
   public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
       System.out.print("Enter a plain text : ");
       String s=sc.nextLine();
       System.out.print("Enter the first offset : ");
       int n1=sc.nextInt();
       while(n1<=1)
       {
       System.out.print("Offset should be strictly positive and greater than 1. Please enter again : ");
       n1=sc.nextInt();
       }
       System.out.print("Enter the second offset : ");
       int n2=sc.nextInt();
       while(n2<=1)
       {
       System.out.print("Offset should be strictly positive and greater than 1. Please enter again : ");
       n2=sc.nextInt();
       }
       int l=s.length();
       int c=0;
       String a="";
       for(int i=0;i<l;i++)
       {
       char x=s.charAt(i);
       if(c%2==0)
       {
       if(Character.isUpperCase(x))
{
char ch=Character.toLowerCase(x);
ch = (char)(((int)ch + n1 - 97) % 26 + 97);
a=a+ch;
c++;
}
else if(Character.isLowerCase(x))
{
char ch=Character.toUpperCase(x);
ch = (char)(((int)ch + n1 - 65) % 26 + 65);
a=a+ch;
c++;
}
else
a=a+x;
       }
       else
       {
       if(Character.isUpperCase(x))
{
char ch=Character.toLowerCase(x);
ch = (char)(((int)ch + n2 - 97) % 26 + 97);
a=a+ch;
c++;
}
else if(Character.isLowerCase(x))
{
char ch=Character.toUpperCase(x);
ch = (char)(((int)ch + n2 - 65) % 26 + 65);
a=a+ch;
c++;
}
else
a=a+x;
       }
       }
       System.out.println("Ciphered Text : "+a);
   }
}

ChemistryExplain “#497 Write a code java to do caesar's code is in Computer science, Ba computer science, Berkeley computer science

ChemistryExplain “#497 Write a code java to do caesar's code is in Computer science, Ba computer science, Berkeley computer science

ChemistryExplain “#497 Write a code java to do caesar's code is in Computer science, Ba computer science, Berkeley computer science

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home