matty-guy
December 24th, 2010, 12:07 AM
Okay, so I'm trying to create a Vigenere encoder, and the program almost works. The programs very basic at the moment, as I want the fundamentals to work first, rather than building the fundamentals into the program.
import java.util.Scanner;
public class grrrr {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input, key, encrypt="";
int inputlength;
System.out.println("\nPlease enter the message.");
input = sc.nextLine();
System.out.println("\nPlease enter the message.");
key = sc.nextLine();
for (int i = 0; i < input.length(); i++) {
int hello = key.charAt(i) - 'a';
int letter = input.charAt(i) - 'a';
int result = (letter + (hello % 26)) ;
result = result + 'a';
encrypt += (char) result;
}
System.out.println("\n" + encrypt);
}
}
The problem is, if I use attack as the input and lemonl as the key, the output is lxopv, where it should actually be lxfopv. The problem persists with inputs and keys of longer length as well. Any idea what's wrong? Thanks.
import java.util.Scanner;
public class grrrr {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input, key, encrypt="";
int inputlength;
System.out.println("\nPlease enter the message.");
input = sc.nextLine();
System.out.println("\nPlease enter the message.");
key = sc.nextLine();
for (int i = 0; i < input.length(); i++) {
int hello = key.charAt(i) - 'a';
int letter = input.charAt(i) - 'a';
int result = (letter + (hello % 26)) ;
result = result + 'a';
encrypt += (char) result;
}
System.out.println("\n" + encrypt);
}
}
The problem is, if I use attack as the input and lemonl as the key, the output is lxopv, where it should actually be lxfopv. The problem persists with inputs and keys of longer length as well. Any idea what's wrong? Thanks.