ЭТО ТО ЧТО Я СДЕЛАЛ
Я пишу программу для шифрования текста. Сначала я удалил пробелы, знаки препинания и преобразовал строку в верхний регистр. Я затем запутываю, например, добавив OB к каждому гласному так, чтобы HEREISTHEMAN стал HOBEOBISTHOBEMOBAN. Затем я кесарево сечение с использованием клавиши +1 Shift, но вместо того, чтобы вернуть IPCFPCJTUIPCFNPCBO. Он вернул "BCDEFGHIJKLMNOPQRSTUVWXYZA. Пожалуйста, оцените любую помощь, чтобы я мог продолжить с остальными шагами. Спасибо.
Это мой код
import java.util.Scanner;
public class ProjectCrypto {
static String text;
public static void main(String[] args) {
System.out.println(normalizeText());
System.out.println(Obify());
System.out.print("Enter shift: ");
Scanner val = new Scanner(System.in);
int key = val.nextInt();
System.out.println(caesarify(Obify(), key));
}
public static String normalizeText(){
Scanner val = new Scanner(System.in);
System.out.println("Write a text to be encrypted below");
text = val.nextLine();
text = text.replaceAll("[^A-Za-z]+", "").toUpperCase();
return text;
}
public static String Obify(){
String ObifiedText = "";// replaces all vowels with "OB" and corresponding vowel
int length = text.length();
for (int i = 0; i < length; i++) {
if (text.charAt(i) == 'A' || text.charAt(i) == 'E' || text.charAt(i) == 'I' // uses for loop to do so
|| text.charAt(i) == 'O' || text.charAt(i)== 'U')
{ObifiedText += "OB";
ObifiedText += text.charAt(i);
} else
ObifiedText += text.charAt(i);
}
return ObifiedText;
}
public static String caesarify(String text, int key) {
String shiftA = shiftAlphabet(key);
return shiftA;
}
public static String shiftAlphabet(int shift) {
int start = 0;
if (shift < 0) {
start = (int) 'Z' + shift + 1;
} else {
start = 'A' + shift;
}
String result = "";
char currChar = (char) start;
for (; currChar <= 'Z'; ++currChar) {
result = result + currChar;
}
if (result.length() < 26) {
for (currChar = 'A'; result.length() < 26; ++currChar) {
result = result + currChar;
}
}
return result;
}
}