嘿家伙我想知道我是否可以得到一些帮助:我试图在一个字节数组内计数十六进制数。我在做什么是我有八个十六进制数字形式的纯文本和相同形式的密文以及密钥的前4个数字。即时尝试使用DES通过强力破解密钥。在字节数组中循环十六进制数字
我的关键是这样的:
[A3 BB 12 44 __ __ __ __]
,我希望它这样开始我想:
[A3 BB 12 44 00 00 00 00]
然后
[A3 BB 12 44 00 00 00 01]
等。我真的不知道如何在十六进制数。在一个字节数组里面!
任何帮助非常感谢!
编辑完成后太大的帮助
这里找到键(我改变了一些东西的名字周围以更好地满足我的程序)
public static void findKey(){
byte [] keyBytes = null;
byte [] pt;
byte [] ct;
codeBreaker KEY = new codeBreaker(new byte[]{(byte)0x01, (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00}, 2);
String plaintext = "Plaintxt";
ct = new byte [] {(byte)0x4A, (byte)0xC4, (byte)0x55, (byte)0x3D, (byte)0xB3, (byte)0x37, (byte)0xCA, (byte)0xB3};
//convert the plain text "Plaintxt" into a hex byte array
String ptHex = asciiToHex(plaintext);
pt = getBytes(ptHex);
//keyBytes = KEY.inc()
//my attempt
/*while(!isKey(pt,keyBytes,ct)){
KEY.inc(); // something like increase the key by 1 and send t back in.
}
*/
//this is your original while loop
/*while (KEY.inc()) {
byte[] bytes = KEY.getBytes();
for (byte b: bytes) {
System.out.printf("%02X ", b);
}
System.out.println();
}
*/
//Final outputs for the findKey method
System.out.println(" Plain Text In Hex Is:");
printByteArray(pt);
System.out.println();
System.out.println(" The Cipher Text Is:");
printByteArray(ct);
System.out.println();
}
,这里是你想出的东西
public codeBreaker(byte[] keyAr, int startIndex) {
this.key = keyAr;
this.startIndex = startIndex;
}
public boolean inc() {
int i;
for (i = key.length-1; i >= startIndex; i--) {
key[i]++;
if (key[i] != 0)
break;
}
// we return false when all bytes are 0 again
return (i >= startIndex || key[startIndex] != 0);
}
public byte[] getBytes() {
return key;
}
我把它们放到一个类中,并将其称为codeBreaker与其他方法(但其他方法不与这个特定部分有什么关系)
*“嘿,想知道如果我能得到一点点智慧帮助” * - 不圆这里的队友。我们都只是“愚蠢的程序员”......就像你:-) :-) – 2013-02-10 05:48:03
@StephenC:为自己说话。我认为自己是一个智力沉重的人,与拉什林博和唐纳德特朗普一起。 – 2013-02-10 05:51:36
尽管如此,一个字节不知道或在意它是否为十六进制,因为这只是字节的字符串表示形式。你能给你更多背景吗?字节数组来自哪里,为什么你不能简单地用for循环遍历它,等等...... – 2013-02-10 05:53:15