目标:解码加密的十六进制,这需要查找未知的单字符密钥
我纯粹是试图通过对每个ascii字符的xOR中的每个字符进行异或来解决问题。我期待得到一个字符串作为我的输出之一。但是,我的catch语句说它返回的每个字符串都不是十六进制。
然后,我计划将这些转换后的十六进制值转换为chars。 如果你能为我提供一些如何解决这个暴行的指导,那将会非常有用。
非常感谢!
//intention of this program is to decrypt this string of encoded hex, find the key, and decrpt the message
//however, its not really working. It doesnt print values prior to 112 even though those values arent blank
// as I checked in debugger
public static void main(String[] args) throws UnsupportedEncodingException
{
String xOr1 = ("1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736");
String xOr = "z({zzz{{z-{z{z{{{}z*{y)~x~x~{{rzsz(";
String result = "";
System.out.println("xOr1 length is " + xOr1.length());
String output = "";
byte[] encoded = xOr1.getBytes();
byte[] decoded;
String sub;
String matches = "(.*)abdef0123456789(.*)";
int hexInt;
for(int k = 0; k< 256;k++)
{
decoded = new byte[encoded.length];
result = "";
System.out.println(k);
for(int j = 0; j<encoded.length; j++)
{
decoded[j] = (byte)((int)encoded[j] ^ k);
result = Arrays.toString(decoded);
}
output = new String(decoded,"UTF-8");
//System.out.println(output);
try
{
for(int i = 0; i< output.length() -2; i++)
{
hexInt = Integer.parseInt(output,16);
System.out.println("You aren't dumb... " + output);
}
}
catch(NumberFormatException nfe)
{
//System.out.println(output);
System.out.println("bad boy");
}
}
}