ちょっとした助けが得られるかどうか知りたかったのですが、バイト配列内で 16 進数でカウントアップしようとしています。私がしていることは、キーの最初の 4 つの数字と同様に、8 つの 16 進数の形式のプレーン テキストと同じ形式の暗号文を持っていることです。そして、DES を使用して、力ずくで鍵をクラックしようとしています。
私のキーは次のようになります。
[A3 BB 12 44 __ __ __ __]
そして、私はそれを次のように開始したいと思います:
[A3 BB 12 44 00 00 00 00]
それから
[A3 BB 12 44 00 00 00 01]
等々。私は16進数で数える方法を本当に知りません。そのバイト配列の中に!
どんな助けでも大歓迎です!
多くの助けを借りて編集
これがfindキーです(プログラムに合わせて周りのものの名前をいくつか変更しました)
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;
}
私はすべて1つのクラスに入れて、私が持っている残りのメソッドでそれをcodeBreakerと呼びました(ただし、他のメソッドはこの特定の部分とは何の関係もありません)