ISC practical papers › ISC 2004 › Question 2
Decoding Secret Message
ISC 2004 Computer Science Practical, Question 2 · Strings
The question
The computer department of the Agency of International Espionage is trying to decode Intercepted messages. The agency’s spies have determined that the enemy encodes Messages by first converting all characters to their ASCII values and then reversing the string.
For example, consider A_z (the underscore is just to highlight the space). The ASCII values of A,, z are 65, 32, 122 respectively. Concatenate them to get 6532122, then reverse this to get 2212356 as the coded message.
Write a program which reads a coded message and decodes it. The coded message will not exceed 200 characters. It will contain only alphabets (A …… Z, and a …….z) and spaces.
ASCII values of A ……Z are 65 ….. 90 and those of a……z are 97 …..122.
Test your Program for the following data and some random data.
SAMPLE DATA:
INPUT: Encoded Message: 2312179862310199501872379231018117927 OUTPUT: THE DECODED MESSAGE: Have a Nice Day
INPUT: Encoded Message: 23511011501782351112179911801562340161171141148 OUTPUT: THE DECODED MESSAGE: Truth Always Wins
Question: ISC 2004 Computer Science Paper 2 (Practical), Question 2, set by the Council for the Indian School Certificate Examinations (CISCE). Solution and video: Vinay Singh.
Java solution
import java.util.*;
class Message{
private String encodedMessage, decodedMessage;
public Message(String encodedMessage){
this.encodedMessage = encodedMessage;
decode();
}
private void decode(){
String temp="";
decodedMessage="";
int number;
for( int index=encodedMessage.length()-1; index>=0; index--){
temp+=encodedMessage.charAt(index);
number=Integer.parseInt(temp);
if(number==' ' || Character.isLetter(number)){
decodedMessage+=(char)number;
temp="";
}
}
}
public String toString(){
return decodedMessage;
}
}
public class ISC2004Q2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("INPUT:\nEncoded Message:");
String encodedMessage = in.next();
Message msg = new Message(encodedMessage);
System.out.println("OUTPUT:\n"+msg);
in.close();
}
}
All these solutions in one free book
Pragmatic Solutions to ISC Computer Science Practical Problems collects every program from 2004 to 2021 in a 202-page PDF.