Java String XOR Decode XORdecode(String res, String key)

Here you can find the source of XORdecode(String res, String key)

Description

XO Rdecode

License

Open Source License

Declaration

public static String XORdecode(String res, String key) 

Method Source Code

//package com.java2s;

public class Main {
    public static String XORdecode(String res, String key) {
        byte[] bs = parseHexStr2Byte(res);
        for (int i = 0; i < bs.length; i++) {
            bs[i] = (byte) ((bs[i]) ^ key.hashCode());
        }//from   w  w  w . j a va2 s  .  c o  m
        return new String(bs);
    }

    public static byte[] parseHexStr2Byte(String hexStr) {
        if (hexStr.length() < 1)
            return null;
        byte[] result = new byte[hexStr.length() / 2];
        for (int i = 0; i < hexStr.length() / 2; i++) {
            int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
            int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
            result[i] = (byte) (high * 16 + low);
        }
        return result;
    }
}

Related

  1. xorDecode(String data, String key)