1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.ninjasoft.magiccodes.plugins;
18
19 import java.text.DecimalFormat;
20
21 /***
22 * Plugin for performing ROT-N on text
23 * @author enigma
24 */
25 public class RotN implements Plugin {
26 private DecimalFormat format = new DecimalFormat("00");
27 public String getName() {
28 return "ROT-N";
29 }
30 public String getDescription() {
31 return "Performs ROT-N text rotations";
32 }
33 public boolean usesKey() {
34 return false;
35 }
36 public boolean isInformational() {
37 return true;
38 }
39 public int[] doAction(int[] in, int[] key) {
40 StringBuffer result = new StringBuffer();
41 for (int rot=0; rot<=26; rot++) {
42 result.append("ROT-");
43 result.append(format.format(rot));
44 result.append(": ");
45 for (int i=0; i<in.length; i++) {
46 int c = in[i];
47 if ((c >= 'a') && (c <= 'z'))
48 c = (c - 'a' + rot) % 26 + 'a';
49 else if ((c >= 'A') && (c <= 'Z'))
50 c = (c - 'A' + rot) % 26 + 'A';
51 else if ((c >= ' ') && (c <= '~'))
52 ;
53 else
54 c = 0;
55 result.append((char) c);
56 }
57 result.append("\n");
58 }
59 int[] resultArray = new int[result.length()];
60 for (int i=0; i<resultArray.length; i++)
61 resultArray[i] = result.charAt(i);
62 return resultArray;
63 }
64
65 }