Page 390 - Computer science 868 Class 12
P. 390
13. Caesar Cipher is an encryption technique which is implemented as ROT13 (‘rotate by 13 places’). It is a simple letter substitution
cipher that replaces a letter with the letter 13 placed after it in the alphabets, with the other characters remaining unchanged.
Write a program to accept a plain text of length L, where L must be greater than 3 and less than 100.
Encrypt the text if valid as per the Caesar Cipher.
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.
14. Write a program to input a sentence and arrange the words of the string in order of their lengths from the shortest to the longest.
15. Write a program to find duplicate characters in a String with the following specifications.
Class name : duplicate
Data Members
String sen : stores a sentence
String newsen : stores the new sentence
Member Methods
void input() : Inputs a sentence
void removedup() : Removes the duplicate characters and stores in newsen
void show() : Prints both the sentences
Previous Years' Questions
1. A class SortAlpha has been defined to sort the words in the sentence in alphabetical order. [ISC 2023]
Example: Input: THE SKY IS BLUE
Output: BLUE IS SKY THE
Some of the members of the class are given below:
Class name : SortAlpha
Data members/instance variable:
sent : to store a sentence
n : integer to store the number of words in a sentence
Methods/Member functions:
SortAlpha() : default constructor to initialise data members with legal initial
value
void acceptsent() : to accept a sentence in UPPER CASE
void sort(SortAlpha P) : sorts the words of the sentence of object P in alphabetical order
and stores the sorted sentence in the current object
void display() : display the original sentence along with the sorted sentence by
invoking the method sort()
Specify the class SortAlpha giving details of the constructor(), void acceptsent(), void sort(SortAlpha) and void display(). Define
a main() function to create an object and call the functions accordingly to enable the task.
Ans. import java.util.*;
class SortAlpha
{
String sent;
int n;
public SortAlpha()
{
sent="";
n=0;
388388 Touchpad Computer Science-XII

