4 Replies - 3919 Views - Last Post: 28 October 2010 - 10:27 PM Rate Topic: -----

#1 Guest_javastudent01*


Reputation:

Java Vigenere Assignment

Posted 28 October 2010 - 04:54 PM

So, I've been working on this project all week but I'm officially stuck. My goal is to create a Vigenere Cipher that prompts the user for a key, an input file, and an output file name.

My biggest problem is that I cannot find a way to apply what the user types in for the key to the input file that they would like to encrypt/decrypt. I've listed a few snippets of my code below. Keep in mind that my professor provided us with a skeleton of blank methods to use.
Any help would be appreciated!
This is the first 3 lines in my getKey method.
//Prompts the user for and returns a valid key for encryption/decryption.
public static String getKey(Scanner console) {
	System.out.println("Key: ");
	String key = console.next();


/Encrypts message in input and outputs encrypted message
//to output based on based on key
public static void encrypt (String key, Scanner input, PrintStream output {

}

//Returns string containing line encrypted using key	
public static String encryptLine(String key, String line){
		Scanner scan = new Scanner(line);
		while (scan.hasNextLine()) {
			line = scan.nextLine();
			
		
		}
		return line;
	}



Edited by macosxnerd101: Please, :code:.

Is This A Good Question/Topic? 0

Replies To: Java Vigenere Assignment

#2 SpeedisaVirus   User is offline

  • Baller

Reputation: 115
  • View blog
  • Posts: 855
  • Joined: 06-October 08

Re: Java Vigenere Assignment

Posted 28 October 2010 - 05:33 PM

Then I suggest you google it and start writing code and come back when you have written some code and need help. Without code there is nothing to help with. That looks like a code skeleton given in an assignment. No attempts to write encrypt.
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12680
  • View blog
  • Posts: 45,863
  • Joined: 27-December 08

Re: Java Vigenere Assignment

Posted 28 October 2010 - 05:34 PM

This site provides an awesome introduction to the Vigenere cipher. On it, you'll see a coordinate plane, with one axis as the keytext and the other as the plaintext. The corresponding letters for (keyTextLetter, plainTextLetter) is a ciphertext letter.
Was This Post Helpful? 0
  • +
  • -

#4 Guest_javastudent01*


Reputation:

Re: Java Vigenere Assignment

Posted 28 October 2010 - 06:44 PM

I know how the Cipher is supposed to work, I just don't know a command that would use the keyphrase to shift the characters in another file. Am I supposed to use a for loop to look at each token in a file? After looking at my code, it looks like I mixed up encrypt and encryptLine.

/Encrypts message in input and outputs encrypted message
//to output based on based on key

public static void encrypt (String key, Scanner input, PrintStream output {
Scanner scan = new Scanner(input)
while (scan.hasNextLine()) { //while there is a next line in the input
    input = scan.nextLine() 
}
for(int i = 0; i<input.length; i++) {
(somehow apply the key to the tokens in the input file)
}


Was This Post Helpful? 0

#5 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java Vigenere Assignment

Posted 28 October 2010 - 10:27 PM

And if you want a GUI interface there is my Secret Code second tutorial

http://www.dreaminco...igenere-square/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1