vigenere tableau, HOW to generate this algorithm in two dimensional array

  • Follow



0 1 2 3 4 5 6 7 .....      25
1 2 3 4 5 6 7 8....   25   0
2 3 4 5 6 7 8 9..24 25 0 1
3 4 5 6.....  .................2
..                                 3
..                               .
..                                  .
...                              ..
25 0 1 2 3 4 5....       24


so basically the first row will be 0 -25
second row will be 1- 0(when it hits 25, it will go to 0 again)
and so forth
column wise it will go from 0 to 25 also

anybody know how to generate this algorithm in java, please help.

0
Reply swq_shan10 (14) 2/8/2007 5:13:33 AM

On 7 Feb 2007 21:13:33 -0800, spidey12345 wrote:
> 0 1 2 3 4 5 6 7 .....      25
> 1 2 3 4 5 6 7 8....   25   0
> 2 3 4 5 6 7 8 9..24 25 0 1
> 3 4 5 6.....  .................2
> .                                 3
> .                               .
> .                                  .
> ..                              ..
> 25 0 1 2 3 4 5....       24

[...]

> anybody know how to generate this algorithm in java, please help.

Do you know how to generate the first row?

There is a relationship between the row number, and the offset used
within the row. Do you not see it? You can use the same code to
generate all 25 rows.

Also, do you know about Java's "remainder" operator?

That said, I don't think that it's necessary to actually generate all
of those rows in order to implement Vigenere.

/gordon

-- 
[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e
0
Reply n.o.t (478) 2/8/2007 7:26:46 AM


On Feb 8, 2:26 am, Gordon Beaton <n...@for.email> wrote:
> On 7 Feb 2007 21:13:33 -0800, spidey12345 wrote:
>
> > 0 1 2 3 4 5 6 7 .....      25
> > 1 2 3 4 5 6 7 8....   25   0
> > 2 3 4 5 6 7 8 9..24 25 0 1
> > 3 4 5 6.....  .................2
> > .                                 3
> > .                               .
> > .                                  .
> > ..                              ..
> > 25 0 1 2 3 4 5....       24
>
> [...]
>
> > anybody know how to generate this algorithm in java, please help.
>
> Do you know how to generate the first row?
>
> There is a relationship between the row number, and the offset used
> within the row. Do you not see it? You can use the same code to
> generate all 25 rows.
>
> Also, do you know about Java's "remainder" operator?
>
> That said, I don't think that it's necessary to actually generate all
> of those rows in order to implement Vigenere.
>
> /gordon
>
> --
> [ don't email me support questions or followups ]
> g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e



i see that, but i want to generate a two dimensional array for a
reason, how would i do it?

i mean it would be nice for you to write the algorithm down, rather
than telling me what to do, because i wanted that 2d array for reason

offset is by 1 to the left each time time, yeah i see that, how would
you write the acutal algorithm, sorry, i guess i just need to see some
code
to understand it


0
Reply swq_shan10 (14) 2/8/2007 10:02:27 AM

spidey12345 wrote:
> On Feb 8, 2:26 am, Gordon Beaton <n...@for.email> wrote:
> 
>>On 7 Feb 2007 21:13:33 -0800, spidey12345 wrote:
>>
>>
>>>0 1 2 3 4 5 6 7 .....      25
>>>1 2 3 4 5 6 7 8....   25   0
>>>2 3 4 5 6 7 8 9..24 25 0 1
>>>3 4 5 6.....  .................2
>>>.                                 3
>>>.                               .
>>>.                                  .
>>>..                              ..
>>>25 0 1 2 3 4 5....       24
>>
>>[...]
>>
>>
>>>anybody know how to generate this algorithm in java, please help.
>>
>>Do you know how to generate the first row?
>>
>>There is a relationship between the row number, and the offset used
>>within the row. Do you not see it? You can use the same code to
>>generate all 25 rows.
>>
>>Also, do you know about Java's "remainder" operator?
>>
>>That said, I don't think that it's necessary to actually generate all
>>of those rows in order to implement Vigenere.
> 
> 
> 
> 
> i see that, but i want to generate a two dimensional array for a
> reason, how would i do it?

Most programming is done by thinking about the problem, breaking it down into 
smaller pieces until you have a small enough piece that you can work on.

> i mean it would be nice for you to write the algorithm down, 

This is one of those "give a fish" or "teach to fish" situations. Your question 
is so elementary that if you are not willing to try and think about it a little 
yourself then you are unlikely to ever get much further.

First reduce the problem to generating the first line in a one dimensional 
array. Once you have done that it will be a lot easier to see how to extend it 
to a two dimensional array.


Here's a start:

Class Vigenere {
     public static void main(String[] args) {
         int index = 0;
         // Do something here that increments index in a loop until it reaches 25
             int value = index;
             System.out.println(index+": "+value);
         // close the loop mentioned above
     }
}

I haven't tried the above, type it in and get it working.

Then replace my comments with the appropriate Java statements.

Once you have that working, work out how to declare an array of integers and 
replace the println with a statement that assigns a value to an element of an array.

Then try thinking about adding another loop corresponding to the other dimension 
of your array. Think about your "offset" and how it could be applied to the 
calculation of the value.

At each step you will have a working program that shows successful completion of 
a small part of the problem.
0
Reply scobloke2 (489) 2/8/2007 10:25:14 AM

On 8 Feb 2007 02:02:27 -0800, spidey12345 wrote:
> i mean it would be nice for you to write the algorithm down, rather
> than telling me what to do, because i wanted that 2d array for reason

I wasn't "telling you what to do" at all. I simply asked some leading
questions to help you help yourself. This is extremely basic stuff.

/gordon

"Build a man a fire and he'll be warm for a day. Set a man on fire and
he'll be warm for the rest of his life." -- Terry Pratchett

-- 
[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e
0
Reply n.o.t (478) 2/8/2007 10:34:43 AM

Thanks guys, i got it to work, would this be efficient, how would i
make this code better


public class test {
	public static void main (String[] args)
	{
		int twoarray[][] = new int[26][26];

		int offset = 0;
		for(int i = 0; i<26; i++)
		{

			for(int j = 0; j<26; j++)
			{
				int value;

			 value = j +offset;
			if(value > 25)
				value = value - 26;

			twoarray[i][j] = value;
			}
			offset++;
		}


		for(int i = 0; i <26; i++)
		{
			for(int j = 0; j <26; j++)
			{
				System.out.print(twoarray[i][j]);
				System.out.print(" ");
			}
		System.out.println();
		}

	}
}

0
Reply swq_shan10 (14) 2/8/2007 11:45:41 AM

spidey12345 wrote:
> Thanks guys, i got it to work, would this be efficient, how would i
> make this code better
> 
> 
> public class test {
>   public static void main (String[] args)
>   {
>     int twoarray[][] = new int[26][26];
> 
>     int offset = 0;
>     for(int i = 0; i<26; i++)
>     {
[...]
> }

Your code already looks very efficient to me. Therefore I would not 
bother to make it faster.
However, I have one suggestion not concerning efficiency, but concerning 
style. There are many so-called "magic" numbers (26 or 25) all over the 
place. You can get around this for example by defining a constant
    final static int N = 26;
and then using that N instead of 26 (and  N-1 instead of 25) in your code.


-- 
Thomas
0
Reply i.dont.like.spam (473) 2/8/2007 12:23:58 PM

6 Replies
14 Views

(page loaded in 0.137 seconds)


Reply: