@@ -91,28 +91,50 @@ private static boolean IsCapitalLatinLetter(char c) {
9191private static boolean IsSmallLatinLetter (char c ) {
9292return c >='a' &&c <='z' ;
9393 }
94+ /**
95+ * @return string array which contains all the possible decoded combination.
96+ */
97+ public static String []bruteforce (String encryptedMessage ) {
98+ String []listOfAllTheAnswers =new String [27 ];
99+ for (int i =0 ;i <=26 ;i ++) {
100+ listOfAllTheAnswers [i ] =decode (encryptedMessage ,i );
101+ }
102+
103+ return listOfAllTheAnswers ;
104+ }
94105
95106public static void main (String []args ) {
96107Scanner input =new Scanner (System .in );
108+ int shift =0 ;
97109System .out .println ("Please enter the message (Latin Alphabet)" );
98110String message =input .nextLine ();
99111System .out .println (message );
100- System .out .println ("Please enter the shift number" );
101- int shift =input .nextInt () %26 ;
102- System .out .println ("(E)ncode or (D)ecode ?" );
112+ System .out .println ("(E)ncode or (D)ecode or (B)ruteforce?" );
103113char choice =input .next ().charAt (0 );
104114switch (choice ) {
105115case 'E' :
106116case 'e' :
117+ System .out .println ("Please enter the shift number" );
118+ shift =input .nextInt () %26 ;
107119System .out .println (
108120"ENCODED MESSAGE IS\n " +encode (message ,shift ));// send our function to handle
109121break ;
110122case 'D' :
111123case 'd' :
124+ System .out .println ("Please enter the shift number" );
125+ shift =input .nextInt () %26 ;
112126System .out .println ("DECODED MESSAGE IS\n " +decode (message ,shift ));
127+ break ;
128+ case 'B' :
129+ case 'b' :
130+ String []listOfAllTheAnswers =bruteforce (message );
131+ for (int i =0 ;i <=26 ;i ++) {
132+ System .out .println ("FOR SHIFT " +String .valueOf (i ) +" decoded message is " +listOfAllTheAnswers [i ]);
133+ }
113134default :
114135System .out .println ("default case" );
115136 }
137+
116138input .close ();
117139 }
118140}