Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How convert this code from Vigenere Cipher to Columnar cipher?

Java
 package vigenere;
import java.util.Scanner;
public class VigenereCipher {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Please enter the key (ONLY CAPITAL LETTERS WITHOUT SPACE)");
        String key = input.nextLine();
        System.out.println("Please enter the text");
        String plainText = input.nextLine(); 
        String e = encryption(plainText, key);
        System.out.println("encryption text is:");
        System.out.println(e);
        System.out.println("decryption text is:");
        System.out.println(decryption(e, key));
    }
 
    static String encryption(String plainText,  String key) {
        String empty = "";
        plainText = plainText.toUpperCase();
        for (int i = 0, j = 0; i < plainText.length(); i++) {
            char x = plainText.charAt(i);
            if (x < 'A' || x > 'Z') {};
            empty += (char)((x + key.charAt(j) - 2 * 'A') % 26 + 'A');
            j = ++j % key.length();
        }
        return empty;
    }
 
    static String decryption(String plainText,  String key) {
        String empty = "";
        plainText = plainText.toUpperCase();
        for (int i = 0, j = 0; i < plainText.length(); i++) {
            char x = plainText.charAt(i);
            if (x < 'A' || x > 'Z') {};
            empty += (char)((x - key.charAt(j) + 26) % 26 + 'A');
            j = ++j % key.length();
        }
        return empty;
    }
}
Posted
Updated 19-Mar-13 7:32am
v2
Comments
Sergey Alexandrovich Kryukov 19-Mar-13 13:42pm    
What would possibly a meaning of "convert" here? :-)
—SA

1 solution

The question does not seem to make sense. You cannot "convert" code. You probably simply need the implementation of Columnar Transposition Cipher (I wonder why):
http://en.wikipedia.org/wiki/Transposition_cipher[^].

—SA
 
Share this answer
 
Comments
Member 9923746 19-Mar-13 14:48pm    
Please help me to solve this question:

Create a small Java program to implement Columnar cipher concept. The program should follow these specifications:
- Allow the user to choose the key.
- Should have two methods called: encrypt and decrypt.
Without the user interface
Sergey Alexandrovich Kryukov 19-Mar-13 15:02pm    
Help with what? What prevents you from doing it by yourself? Is there any reason why should I do your work?
Perhaps you can do it by yourself, will face some problems, than you can ask your questions.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900