我在哪里可以找到Vigenere密码的Java源代码?

在我的应用程序中,我想实现一些加密.因此我需要Vigenere密码的代码.有谁知道我在哪里可以找到 Java的源代码

解决方法

这是Vigenere密码类,你可以使用它,只需调用加密和解密函数
代码来自 Rosetta Code.
public class VigenereCipher {
    public static void main(String[] args) {
        String key = "VIGENERECIPHER";
        String ori = "Beware the Jabberwock,my son! The jaws that bite,the claws that catch!";
        String enc = encrypt(ori,key);
        System.out.println(enc);
        System.out.println(decrypt(enc,key));
    }

    static String encrypt(String text,final String key) {
        String res = "";
        text = text.toupperCase();
        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();
        }
        return res;
    }

    static String decrypt(String text,j = 0; i < text.length(); i++) {
            char c = text.charat(i);
            if (c < 'A' || c > 'Z') continue;
            res += (char)((c - key.charat(j) + 26) % 26 + 'A');
            j = ++j % key.length();
        }
        return res;
    }
}

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...