Caesar Encryption Decryption
843811Jan 24 2006 — edited Jan 26 2006Well, Hi All!!
I hope you can help on this problem I have!
I'm trying to program a tool with a dynamic Caesar encryption of a text.
I reads it's caesar key consisting of 36 chars into an array and reads the text from a file into an array.
Now the Encryption works fine with the switch function but the decryption is giving me a hard time.
Switch won't take an array as a case so I have to do the workaround around switch.
Does anybody have an Idea how to do this?
I'll put up the encyption subroutine and the direction in which I've been working for the decretiption Subroutine:
Encryption:
public static void geheim(char[] text,int count, int menueint,char[]schluessel) {
i=0;
do {
switch(text) {
case 'a': text= schluessel[0]; break;
case 'b': text= schluessel[1]; break;
case 'c': text= schluessel[2]; break;
case 'd': text= schluessel[3]; break;
case 'e': text= schluessel[4]; break;
case 'f': text= schluessel[5]; break;
case 'g': text= schluessel[6]; break;
case 'h': text= schluessel[7]; break;
case 'i': text= schluessel[8]; break;
case 'j': text= schluessel[9]; break;
case 'k': text= schluessel[10]; break;
case 'l': text= schluessel[11]; break;
case 'm': text= schluessel[12]; break;
case 'n': text= schluessel[13]; break;
case 'o': text= schluessel[14]; break;
case 'p': text= schluessel[15]; break;
case 'q': text= schluessel[16]; break;
case 'r': text= schluessel[17]; break;
case 's': text= schluessel[18]; break;
case 't': text= schluessel[19]; break;
case 'u': text= schluessel[20]; break;
case 'v': text= schluessel[21]; break;
case 'w': text= schluessel[22]; break;
case 'x': text= schluessel[23]; break;
case 'y': text= schluessel[24]; break;
case 'z': text= schluessel[25]; break;
case '1': text= schluessel[26]; break;
case '2': text= schluessel[27]; break;
case '3': text= schluessel[28]; break;
case '4': text= schluessel[29]; break;
case '5': text= schluessel[30]; break;
case '6': text= schluessel[31]; break;
case '7': text= schluessel[32]; break;
case '8': text= schluessel[33]; break;
case '9': text= schluessel[34]; break;
case '0': text= schluessel[35]; break;
default: System.out.println("a"); geht=1;
}
i++;
} while (i<count);
text is the array in which my to be encrypted text is in.
schluessel is the array with my caesar key.
Decryption:
public static void klar(char[] text,int count, int menueint) {
i=0;
//String schluessela= new String(schluessel[0]).stringValue;
do {
//String textstr = new String(text).stringValue;
//for (i >< length;i++) {
// Integer schluesselint.indexOf(textstr.charAt(i))
// switch(schluesselint) {
// case
int a = new Integer(schluessel[0]).intValue();
int b = new Integer(schluessel[1]).intValue();
int c = new Integer(schluessel[2]).intValue();
int d = new Integer(schluessel[3]).intValue();
int e = new Integer(schluessel[4]).intValue();
int f = new Integer(schluessel[5]).intValue();
int g = new Integer(schluessel[6]).intValue();
int h = new Integer(schluessel[7]).intValue();
int ii = new Integer(schluessel[8]).intValue();
int j = new Integer(schluessel[9]).intValue();
int k = new Integer(schluessel[10]).intValue();
int l = new Integer(schluessel[11]).intValue();
int m = new Integer(schluessel[12]).intValue();
int n = new Integer(schluessel[13]).intValue();
int o = new Integer(schluessel[14]).intValue();
int p = new Integer(schluessel[15]).intValue();
int q = new Integer(schluessel[16]).intValue();
int r = new Integer(schluessel[17]).intValue();
int s = new Integer(schluessel[18]).intValue();
int t = new Integer(schluessel[19]).intValue();
int u = new Integer(schluessel[20]).intValue();
int v = new Integer(schluessel[21]).intValue();
int w = new Integer(schluessel[22]).intValue();
int x = new Integer(schluessel[23]).intValue();
int y = new Integer(schluessel[24]).intValue();
int z = new Integer(schluessel[25]).intValue();
int aa = new Integer(schluessel[26]).intValue();
int bb = new Integer(schluessel[27]).intValue();
int cc = new Integer(schluessel[28]).intValue();
int dd = new Integer(schluessel[29]).intValue();
int ee = new Integer(schluessel[30]).intValue();
int ff = new Integer(schluessel[31]).intValue();
int gg = new Integer(schluessel[32]).intValue();
int hh = new Integer(schluessel[33]).intValue();
int jj = new Integer(schluessel[34]).intValue();
int kk = new Integer(schluessel[35]).intValue();
double ka = new Double(text[49]).doubleValue();
char 'ka' = new Character(ka).charValue();
char[] textdouble = {ka};
System.out.println(textdouble);
//char a = new Character(a).charValue();
System.out.println(ii);
System.out.println(ka);
System.out.println(ii);
//switch(text) {
//case a
//System.out.println(a);
//}
i++;
}while (i<length);
I've been trying to convert it to an integer and then compare it with the Integer of the char on array position one and so on but it's probably wrong.
Please Help Me
Thanks,
Lukasio
PS: Excuse my misspelling I'm not from the US>