加密字符13次JavaFX

加密字符13次JavaFX,java,javafx,char,Java,Javafx,Char,我在加密13个字符后的代码时遇到问题。该代码应该更改文本字段中键入的内容,每个字符加密13个字符。例如,abc被加密为nop。问题是。 我认为方法就是问题所在。现在,我意识到我认为它没有13个字符 import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene

我在加密13个字符后的代码时遇到问题。该代码应该更改文本字段中键入的内容,每个字符加密13个字符。例如,
abc
被加密为
nop
。问题是。 我认为方法就是问题所在。现在,我意识到我认为它没有13个字符

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

    public class Encrypt13 extends Application {
        @Override
        public void start(Stage primaryStage) {



                // add a gridpane
                GridPane grid = new GridPane();
                grid.setPadding(new Insets(10, 10, 10, 10));



            // add a label for original message top left side
            Label label = new Label("Original Message: ");
            GridPane.setConstraints(label, 0, 0);

            // add label2 for message encrypted
            Label label2 = 

        new Label("Encrpyted Message: ");
        GridPane.setConstraints(label2, 0, 2);

        // add input of text to be encrypted right side of label
        TextField textfield = new TextField();
        GridPane.setConstraints(textfield, 2, 0);

        // add text that will be event handled below textfield
        Label text = new Label();
        GridPane.setConstraints(text, 2, 2);

        // add it to the parent
        grid.getChildren().addAll(label, label2, textfield, text);

        // add an event
        textfield.setOnKeyPressed(e -> {
            // add event with Enter pressed to add arrays compared and added to get 13
            // characters
            char[] newArray = new char[textfield.getLength()];
            if (e.getCode() == KeyCode.ENTER) {
                // this is for the array to get the number checked and added to i char
                for (int p = 0; p < textfield.getLength(); p++) {
                    // this is to get the char i start by the typed from the char until the length
                    // incremented by the method getAllAlpha
                    // which has all alphabets in parameters of the typed with the p number at the
                    // charAt
                    for (char i = textfield.getText().charAt(p); i < textfield.getText().charAt(p) + 1; i += getAllAlpha(textfield.getText(), p)) {
                        newArray[p] += i;
                        text.setText(new String (newArray));
                    }
                }
            }
        });

        // set a scene and place show it
        Scene scene = new Scene(grid, 400, 400);
        primaryStage.setTitle("Encrypt13");
        primaryStage.setScene(scene);
        primaryStage.show();

    }

    public static char getAllAlpha(String q, int x) {
        String alpha = "";
        int i;
        for(i = 0; i <= 255; i++)
        {
            alpha+=(char)i;
        }

        return alpha.charAt(Character.getNumericValue(q.charAt(x)));
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}
导入javafx.application.application;
导入javafx.geometry.Insets;
导入javafx.scene.scene;
导入javafx.scene.control.Label;
导入javafx.scene.control.TextField;
导入javafx.scene.input.KeyCode;
导入javafx.scene.layout.GridPane;
导入javafx.stage.stage;
公共类Encrypt13扩展应用程序{
@凌驾
公共无效开始(阶段primaryStage){
//添加网格窗格
GridPane grid=新建GridPane();
网格设置填充(新的插图(10,10,10,10));
//为原始邮件左上方添加标签
标签=新标签(“原始邮件:”);
setConstraints(标签,0,0);
//为加密邮件添加标签2
标签标签2=
新标签(“加密邮件:”);
setConstraints(标签2,0,2);
//在标签右侧添加要加密的文本输入
TextField TextField=新的TextField();
setConstraints(textfield,2,0);
//在textfield下面添加将被事件处理的文本
标签文本=新标签();
setConstraints(文本,2,2);
//将其添加到父级
grid.getChildren().addAll(标签、标签2、文本字段、文本);
//添加一个事件
textfield.setOnKeyPressed(e->{
//按Enter键添加事件以添加比较的数组,并添加以获取13
//人物
char[]newArray=new char[textfield.getLength()];
如果(例如getCode()==KeyCode.ENTER){
//这是为了让数组检查数字并将其添加到i char中
对于(int p=0;p对于(i=0;i使用
char
s支持与其他数值类型相同的操作,以及a-z和a-z分别是连续值的事实

您可以使用
%
运算符将字符保持在所需范围内,并环绕过大的值

final int rotationDistance = 13;
final int alphabetCharCount = ('Z' - 'A' + 1);

// add an event
textfield.setOnAction(e -> {
    char[] chars = textfield.getText().toCharArray();

    // rotate chars in [a-zA-Z]
    for (int i = 0; i < chars.length; i++) {
        char c = chars[i];
        if (c >= 'A' && c <= 'Z') {
            chars[i] = (char) ((c - 'A' + rotationDistance) % alphabetCharCount + 'A');
        } else if (c >= 'a' && c <= 'z') {
            chars[i] = (char) ((c - 'a' + rotationDistance) % alphabetCharCount + 'a');
        }
    }
    text.setText(new String(chars));
});
final int rotationDistance=13;
最终整数alphabetCharCount=('Z'-'A'+1);
//添加一个事件
textfield.setOnAction(e->{
char[]chars=textfield.getText().toCharArray();
//在[a-zA-Z]中旋转字符
for(int i=0;i='A'&&c='A'&&c='A'&&c'Z')?(char)(c-alphabetCharCount):c;
} ...

使用
char
s支持与其他数值类型相同的操作,以及a-z和a-z分别是连续值的事实

您可以使用
%
运算符将字符保持在所需范围内,并环绕过大的值

final int rotationDistance = 13;
final int alphabetCharCount = ('Z' - 'A' + 1);

// add an event
textfield.setOnAction(e -> {
    char[] chars = textfield.getText().toCharArray();

    // rotate chars in [a-zA-Z]
    for (int i = 0; i < chars.length; i++) {
        char c = chars[i];
        if (c >= 'A' && c <= 'Z') {
            chars[i] = (char) ((c - 'A' + rotationDistance) % alphabetCharCount + 'A');
        } else if (c >= 'a' && c <= 'z') {
            chars[i] = (char) ((c - 'a' + rotationDistance) % alphabetCharCount + 'a');
        }
    }
    text.setText(new String(chars));
});
final int rotationDistance=13;
最终整数alphabetCharCount=('Z'-'A'+1);
//添加一个事件
textfield.setOnAction(e->{
char[]chars=textfield.getText().toCharArray();
//在[a-zA-Z]中旋转字符
for(int i=0;i='A'&&c='A'&&c='A'&&c'Z')?(char)(c-alphabetCharCount):c;
} ...