//Vigenère Cipher (Java)
import java.util.Scanner;

public class Main {
    static String encrypt(String text, String key) {
        String res = "";
        text = text.toUpperCase();
        key = key.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 + 1) % key.length();
        }
        return res;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Key: ");
        String key = sc.nextLine();
        System.out.print("Text: ");
        String text = sc.nextLine();
        System.out.println("Encrypted: " + encrypt(text, key));
    }
}
