Note that there are some explanatory texts on larger screens.

plurals
  1. POCycle through hex numbers in Byte array
    primarykey
    data
    text
    <p>Hey guys I wanted to know if i could get a little help: Im trying to count up in hex inside of a byte array. What im doing is i have the plain text in the form of 8 hex numbers and the cipher text in the same form as well as the first 4 numbers of the key. And im trying to use the DES to crack the key via brute force.</p> <p>my key looks like this:</p> <pre><code>[A3 BB 12 44 __ __ __ __] </code></pre> <p>and i want it to start like this i suppose:</p> <pre><code>[A3 BB 12 44 00 00 00 00] </code></pre> <p>then</p> <pre><code>[A3 BB 12 44 00 00 00 01] </code></pre> <p>and so on. I just dont really know how to count in hex. inside of a byte array at that!</p> <p>any help is much appreciated!</p> <p><strong>EDITED AFTER MUCH HELP</strong></p> <p>here is find key ( i changed some of the names of things around to better suit my program)</p> <pre><code>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(); } </code></pre> <p>and here is the stuff you came up with</p> <pre><code> public codeBreaker(byte[] keyAr, int startIndex) { this.key = keyAr; this.startIndex = startIndex; } public boolean inc() { int i; for (i = key.length-1; i &gt;= startIndex; i--) { key[i]++; if (key[i] != 0) break; } // we return false when all bytes are 0 again return (i &gt;= startIndex || key[startIndex] != 0); } public byte[] getBytes() { return key; } </code></pre> <p>which I all put into one class and called it codeBreaker with the rest of the methods i have (but those other ones dont have anything to do with this specific part)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload