我在哪里可以找到Java源代码code代表的Vigenere密码? [英] Where can I find the Java source code for the Vigenere cipher?

查看:221
本文介绍了我在哪里可以找到Java源代码code代表的Vigenere密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我想实现一些加密。因此,我需要code的V @ genere加密。有谁知道在哪里可以找到源头$ C $下的Java?

in my app I wanted to implement some enciphering. Therefore I need the code for the Vigenere cipher. Does anyone know where I can find that source code for Java?

推荐答案

这是V @ genere加密类,你可以使用它,只需调用加密和解密功能: 在code是罗塞塔code

This is Vigenere cipher Class, you can use it, just call encrypt and decrypt function : The code is from 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, 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) + 26) % 26 + 'A');
            j = ++j % key.length();
        }
        return res;
    }
}

这篇关于我在哪里可以找到Java源代码code代表的Vigenere密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆