暗号化テキストに解読する必要があるテキスト行があります。
私のテキスト行がabc def ghijklm n opq rstu vwx yz
次のような出力が必要です。aei qu c k rvzdhmptxbfjn y glosm
「キー」を 5 と入力したとします。コードは、テキスト ファイルからのテキストの文字列の配列の 5 番目ごとの要素を入力します。
これは私が思いついたコードであり、何をすべきかで壁にぶつかりました。
import java.io.*;
import java.util.*;
public class Files1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int key;
System.out.print("Enter file: ");
String fileName = input.nextLine();
System.out.print("Please enter your Cipher Key: ");
key = input.nextInt();
Scanner inputStream = null;
System.out.println("File name is: " + fileName);
try {
inputStream = new Scanner(new File(fileName));
} catch (FileNotFoundException e) {
System.out.println("Error opening the file" + fileName);
System.exit(0);
}
while (inputStream.hasNextLine()) {
String text = inputStream.nextLine();
System.out.println(text);
char arrayText[] = text.toCharArray();
for (int i = 0; i < arrayText.length; i += key) {
System.out.print("\n" + arrayText[i]);
}
}
}
}
コンソールで何が起こっているかは次のとおりです。
Enter file: abc.txt
File name is: abc.txt
abc def ghijklm n opq rstu vwx yz
a
e
i
q
u