-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion2325.java
More file actions
43 lines (38 loc) · 927 Bytes
/
Copy pathQuestion2325.java
File metadata and controls
43 lines (38 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Author: Ananthanarayanan R
Section: Algorthms
Question: 2325
*/
public class Question2325
{
public static String decodeMessage(String key, String message)
{
String sb = "";
for(int i = 0;i<key.length();i++)
{
if(sb.indexOf(key.charAt(i))==-1 && key.charAt(i)!= ' ')
sb+=key.charAt(i);
if(sb.length()==26)
break;
}
StringBuffer result = new StringBuffer();
for(int i = 0;i<message.length();i++)
{
if(message.charAt(i) == ' ')
result.append(' ');
else
{
result.append((char)(sb.indexOf(message.charAt(i))+97));
}
}
return result.toString();
}
public static void main(String[] args)
{
System.out.println("Main Method starts");
String key = "eljuxhpwnyrdgtqkviszcfmabo";
String message = "zwx hnfx lqantp mnoeius ycgk vcnjrdb";
String result = decodeMessage(key,message);
System.out.println(result);
}
}