例如,如果我提交字符串" TEST3>"它将为您提供#4; $ 4%DO"回来,如果你再加密了#4;#4 $%DO"它会给你" TEST3>"背部。但是,如果您输入" TEsT"它会给你"#4%"返回(注意它跳过了'字符),如果你用程序重新加密,你会得到" TERQ"回来因为它错过了'。任何人都可以告诉我为什么?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cryptomatic2;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* @author Zach
*/
public class Cryptomatic2 extends Application {
@Override
public void start(Stage primaryStage) {
String key = "wq";
GridPane root = new GridPane();
Label inputLabel = new Label("Input");
TextArea input = new TextArea();
input.setMinSize(400, 200);
Button encrypt = new Button("Encrypt");
encrypt.setMinSize(100, 100);
Button decrypt = new Button("Decrypt");
decrypt.setMinSize(100, 100);
Label outputLabel = new Label("Output");
TextArea output = new TextArea();
output.setMinSize(400, 200);
root.add(inputLabel, 0, 0);
root.add(input, 0, 1);
root.add(encrypt, 0, 2);
root.add(decrypt, 1, 2);
root.add(outputLabel, 0, 3);
root.add(output, 0, 4);
Scene scene = new Scene(root, 800, 800);
primaryStage.setTitle("Cryptomatic");
primaryStage.setScene(scene);
primaryStage.show();
encrypt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
String source = input.getText();
String newString = "";
if(source.length() % 2 != 0){
source = source + " ";
}
for(int i = 0; i < source.length(); i+=2){
char value1 = source.charAt(i);
char value2 = source.charAt(i+1);
char key1 = key.charAt(0);
char key2 = key.charAt(1);
int newValue1 = value1 ^ key1;
int newValue2 = value2 ^ key2;
String encrypted1 = Character.toString((char) newValue1);
String encrypted2 = Character.toString((char) newValue2);
newString = newString + encrypted1 + encrypted2;
}
output.setText(newString);
}
});
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}