Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: mod 95 vigninere cipher

1. ## mod 95 vigninere cipher

Hi guys i have never used mod befopre and baiscally

i need the number to wrap around 1- 95 so if i have a sum 6-10 it would come round to +4 instead of -4 or if we have 27-30 its

I have this bit of code which is used to decrypt a vigniere cipher i use a vigenere square which is 95x95 and to decrypt it.

im trying to follow this formular :

P_i \equiv (C_i - K_i) \pmod {26}

Vigenère cipher - Wikipedia, the free encyclopedia

"Decryption is performed by going to the row in the table corresponding to the key, finding the position of the ciphertext letter in this row, and then using the column's label as the plaintext. For example, in row L (from LEMON), the ciphertext L appears in column A, which is the first plaintext letter. Next we go to row E (from LEMON), find the ciphertext X in column T, which is the second plaintext letter.

Vigenère can also be viewed algebraically. If the letters A–Z are taken to be the numbers 0–25, and addition is performed modulo 26, then Vigenère encryption can be written,"

 for(int i=0; i<keyY.length; i++)
{
Ykey[i]= (keyY[i] - 32); //works out row
Xcipher[i]= (cipherX[i] - 32); //work out coloum
columnarray[i] =(Xcipher[i]-Ykey[i]+); // THIS IS THE bt where i need mod95
System.out.printf("%4s", columnarray[i]);

}

2. ## Re: mod 95 vigninere cipher

i have had a look at various ways but i dont really understand how to use the %

3. ## Re: mod 95 vigninere cipher

Are you talking about the modulus operator (that's denoted by the % sign)?

5 % 3; // performs "5 modulo 3", returns the remainder of 5/3, or 2.

4. ## Re: mod 95 vigninere cipher

well it says mod not sure if it can be done using modulus

5. ## Re: mod 95 vigninere cipher

Normally in computer science mod is the short way of saying modulus (or modulo, depending on the conjugation), and in Java this is denoted with the % operator.

A modulo operation will naturally limit you to a range [0,x) (where x is the divisor, using set inclusion/exclusion notation).

So if you wanted a range [1, 95], you can translate this to num % 95 + 1;