Where can I find the Java source code for Vigenere encryption?

In my application, I wanted to implement some encryption. Therefore, I need code to encrypt Vigenere. Does anyone know where I can find this source code for Java?

+6
source share
3 answers

This is the Vigenere encryption class, you can use it, just call the encryption and decryption function: Code 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; } } 
+11
source

Here is a link to the implementation of the Vigenere Cipher Code Example Java code for encryption and decryption using Vigenere Cipher , in addition, I cannot recommend using Vigenere Cipher as encryption.

I recommend jBCrypt .

+2
source

Source: https://habr.com/ru/post/919773/


All Articles