如何从vigenere转换为Columnar密码? [英] How convert from vigenere to Columnar cipher ?
本文介绍了如何从vigenere转换为Columnar密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将此代码从Vigenere Cipher转换为Columnar密码?
How convert this code from Vigenere Cipher to Columnar cipher?
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;
}
}
推荐答案
这个问题似乎没有意义。你不能转换代码。你可能只需要实现 Columnar Transposition Cipher (我想知道为什么):
http://en.wikipedia.org/wiki/Transposition_cipher [ ^ ]。
-SA
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
这篇关于如何从vigenere转换为Columnar密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文