如何通过字符串旋转和移位实现特定的Vigenere密码

时间:2019-06-01 22:10:55

标签: java

我正在尝试将所有部分放在一起以完成实现一个类,该类利用带有一系列特殊条件的Vigenere密码。

我已经收集了解决方案的大多数元素,但是需要一些帮助将它们整合在一起。我是Java新手。

public class VigenereCipher {
    public static void main(String[] args) {
        String key = "abc"; 
        String origin = "Some Sample ** String!";
        int Shift = 2;
        String enc = encrypt(origin, key);
    static String encrypt(String text, final String key) {
        String res = "";
        text = text.toString();
        for (int i = 0, j = 0; i < text.length(); i++) {
            char c = text.charAt(i);
            if (c < 'A' || c > 'Z') continue;
            res += (char)((c + key.charAt(j) - 2 * 'A') % 26 + 'A');
            j = ++j % key.length();
            System.out.println(res);
        }
        return res;

    }
  static String rotateLeft(String str, int d)
   {
        String rotateAnswer = str.substring(d) + str.substring(0, d);
        return answer;
   }

0 个答案:

没有答案