小编use*_*067的帖子

将int转换为String,然后使用XOR对其进行加密

我正在尝试将整数转换为字符串,然后使用XOR加密对字符串进行加密.但是当我再次解密我的Strin时,我得到了一个不同的答案,即我在加密之前输入的字符串,我不知道我做错了什么?

public class Krypte {
public static void main (String [] args) {
    int i = 12345;

    String k = Integer.toString(i);
    String G = secure(k.getBytes());
    System.out.println("Encrypted: " + G);

    String U = secure(G.getBytes());
    System.out.println("Decrypted: " + U);
    int X = Integer.parseInt(U);
    System.out.println("As an int: " + X);

}

public static String secure(byte[] msg) {
    // Variables
    int outLength = msg.length;
    byte secret = (byte) 0xAC; // same as 10101100b (Key)
    // XOR kryptering
    for (int i = 0; i < …
Run Code Online (Sandbox Code Playgroud)

java string encryption int character-encoding

2
推荐指数
1
解决办法
1278
查看次数

标签 统计

character-encoding ×1

encryption ×1

int ×1

java ×1

string ×1