Page 360 - Computer science 868 Class 12
P. 360

Test your program with the sample data and some random data.
              Example 1:

              INPUT:

              Hello! How are you?
              OUTPUT:

              The cipher text is:
              Uryyb! Ubj ner lbh?

              Example 2
              INPUT:

              Encryption helps to secure data.

              OUTPUT:
              The cipher text is:

              Rapelcgvba urycf gb frpher qngn.

              Example 3
              INPUT:

              You
              OUTPUT:

              INVALID LENGTH
                  import java.util.*;
                  class change
                  {
                      public static void main()
                      {
                          Scanner sc = new Scanner(System.in);
                          StringBuffer strbuf = new StringBuffer();
                          String str;
                          int len,i;
                          char ch;
                          System.out.println("Enter a sentence :");
                          str = sc.nextLine();
                          len = str.length();
                          if (len <= 3 || len >= 100)
                          {
                              System.out.println("INVALID LENGTH");
                              return;
                          }
                          for (i = 0; i < len; i++)
                          {
                              ch = str.charAt(i);
                              if ((ch >= 'A' && ch <= 'M') || (ch >= 'a' && ch <= 'm'))
                              {                strbuf.append((char)(ch + 13));            }
                              else if ((ch >= 'N' && ch <= 'Z') || (ch >= 'n' && ch <= 'z'))


                358358  Touchpad Computer Science-XII
   355   356   357   358   359   360   361   362   363   364   365