Java 我的加密跳过了小写字母
例如,如果我向程序提交字符串“TEST3>,它将返回“#4$%DO”,如果您重新加密“#4$%DO”,它将返回“TEST3>”。但是,如果您输入“TEsT”,它将返回“#4%”(请注意,它跳过了“s”字符),如果您用程序重新加密,您将返回“TERQ”,因为它缺少“s”。有人能告诉我为什么吗Java 我的加密跳过了小写字母,java,encryption,javafx,Java,Encryption,Javafx,例如,如果我向程序提交字符串“TEST3>,它将返回“#4$%DO”,如果您重新加密“#4$%DO”,它将返回“TEST3>”。但是,如果您输入“TEsT”,它将返回“#4%”(请注意,它跳过了“s”字符),如果您用程序重新加密,您将返回“TERQ”,因为它缺少“s”。有人能告诉我为什么吗 /* * To change this license header, choose License Headers in Project Properties. * To change this tem
/*
* 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);
}
}
/*
*要更改此许可证标题,请在“项目属性”中选择“许可证标题”。
*要更改此模板文件,请选择工具|模板
*然后在编辑器中打开模板。
*/
包密码;
导入javafx.application.application;
导入javafx.event.ActionEvent;
导入javafx.event.EventHandler;
导入javafx.scene.scene;
导入javafx.scene.control.Button;
导入javafx.scene.control.Label;
导入javafx.scene.control.TextArea;
导入javafx.scene.layout.GridPane;
导入javafx.scene.layout.StackPane;
导入javafx.stage.stage;
/**
*
*@作者扎克
*/
公共类加密扩展了应用程序{
@凌驾
公共无效开始(阶段primaryStage){
String key=“wq”;
GridPane root=新的GridPane();
标签输入标签=新标签(“输入”);
TextArea输入=新的TextArea();
输入.setMinSize(400200);
按钮加密=新按钮(“加密”);
encrypt.setMinSize(100100);
按钮解密=新按钮(“解密”);
解密.setMinSize(100100);
标签输出标签=新标签(“输出”);
TextArea输出=新TextArea();
输出.setMinSize(400200);
添加(inputLabel,0,0);
root.add(输入,0,1);
root.add(加密,0,2);
root.add(解密,1,2);
添加(outputLabel,0,3);
root.add(输出,0,4);
场景=新场景(根,800800);
初级阶段。设置标题(“加密”);
初级阶段。场景(场景);
primaryStage.show();
encrypt.setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent t){
String source=input.getText();
字符串newString=“”;
if(source.length()%2!=0){
source=source+“”;
}
对于(int i=0;i
使用您的测试数据和“这是一个测试”
对我来说效果不错<代码>测试不会生成#4%
,但是#4%
,在字符串
(ascii字符4)中有一个无法读取的字符(空格所在的位置),您需要限制加密以生成可显示范围内的字符,或者以更好的方式显示字符串manner@MadProgrammer以更好的方式显示字符串是什么意思?一些将显示缺少的字符的东西,例如使用unicode字符“4”:; 将字符串显示为#4%代码>,或者显示它们时使用十六进制字符,或者其他任何。。。