8 Replies - 1862 Views - Last Post: 04 November 2009 - 01:09 PM Rate Topic: ***-- 2 Votes

#1 hewjazz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-November 09

Creating Keyword for Vigenere Cipher

Post icon  Posted 04 November 2009 - 12:03 PM

I am working on a code that will decrypt and encrypt a string using a vigenere cipher and the user must input a keyword to use to encrypt it. The problem i am having is that i cant figure out how to match the keyword length to the string i am encodings length. I remember my teacher saying something about the modulus function but i cant remember. Any help would be appreciated.
Thanks

This post has been edited by hewjazz: 04 November 2009 - 12:14 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Creating Keyword for Vigenere Cipher

#2 hewjazz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-November 09

Re: Creating Keyword for Vigenere Cipher

Posted 04 November 2009 - 12:28 PM

Maybe using a for statement to copy the key into an array until it reaches the length of the string to be encrypted?
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: Creating Keyword for Vigenere Cipher

Posted 04 November 2009 - 12:30 PM

I think this is what you mean:

Key: Hello
Plaintext: Macosxnerd101

Relation:
H e l l o H e l l o H e l
M a c o s x n e r d 1 0 1

If you need any more help, feel free to post. Remember to include your code.

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
Was This Post Helpful? 0
  • +
  • -

#4 hewjazz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-November 09

Re: Creating Keyword for Vigenere Cipher

Posted 04 November 2009 - 12:46 PM

yes that is exactly what i am looking to get sry i didnt put the code up to start with

		String key = new String("ABCD");
		char[] arrKey = key.toCharArray();


i have this which will work if the key put in is the same length.

yes that is exactly what i am looking to get sry i didnt put the code up to start with


		String key = new String("ABCD");
		char[] arrKey = key.toCharArray();



i have this which will work if the key put in is the same length.
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: Creating Keyword for Vigenere Cipher

Posted 04 November 2009 - 12:50 PM

You might consider using String concatenation in combination with the charAt() method. Something like:

public String modifyKey(String key, int plainLength){
   int i = 0; 
   String temp = key;
   while(key.length() < plainLength){
	   temp += key.charAt(i); //add the next character to temp
	   i = (i+1)%(key.length()-1);  //go to the next char in key, resetting to 0 after reaching the end
	   }
   return temp;
}


Was This Post Helpful? 0
  • +
  • -

#6 hewjazz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-November 09

Re: Creating Keyword for Vigenere Cipher

Posted 04 November 2009 - 12:54 PM

thanks im gonna give that a try.
Was This Post Helpful? 0
  • +
  • -

#7 hewjazz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-November 09

Re: Creating Keyword for Vigenere Cipher

Posted 04 November 2009 - 01:00 PM

now as for encrypting it, subtracting 65 from the key char ascii value and adding it to the plain text char ascii value should work?

now as for encrypting it, subtracting 65 from the key char ascii value and adding it to the plain text char ascii value should work?
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,466
  • Joined: 27-December 08

Re: Creating Keyword for Vigenere Cipher

Posted 04 November 2009 - 01:02 PM

Show us your good faith effort and we'll be glad to help. Otherwise, good luck!

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
Was This Post Helpful? 0
  • +
  • -

#9 hewjazz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-November 09

Re: Creating Keyword for Vigenere Cipher

Posted 04 November 2009 - 01:09 PM

if(messageCharValue >= 65 && messageCharValue <= 90){
encrCharValue = (keyCharValue - 65) + messageCharValue;
}
encrChar = (char)encrCharValue;
encrMessage = encrMessage + encrChar;
keyIndex++;


This post has been edited by hewjazz: 04 November 2009 - 01:09 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1