Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>@jwd, @jscode Thanks a lot for your help. To jwd: I got the idea from your code. Seemed pretty simple logic after I read it.. :-) Wonder why I didnt think of that. Well, I did polish your idea a little bit and it works fine now in Java. If anyone has any suggestions, please let me know. THANKS.. P.S.: The testing part is very primitive. I print the bit values. I did it manually for a couple of examples and used the same as input and it works fine.</p> <p>=============================================</p> <pre><code>public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter an 8 char key: "); String input; try { // get key, key.length()&gt;=8 chars input = br.readLine(); if (input.length() &lt; 8) { System.out.println("Key &lt; 8B. Exiting. . ."); System.exit(1); } // java char has 16 bits instead of 8 bits as in C, // so convert it to 8 bit char by getting lower order byte &amp; // discarding higher order byte char[] inputKey = input.toCharArray(); byte[] key64 = new byte[8]; byte[] key56 = new byte[7]; // consider only first 8 chars even if input &gt; 8 for (int counter = 0; counter &lt; 8; counter++) key64[counter] = (byte) inputKey[counter]; System.out.print("\n$$ " + new String(key64) + " $$\n"); // converting 64bit key to 56 bit key for (int counter = 0; counter &lt; KEY_LENGTH - 1; counter++) { key64[counter] = (byte) (key64[counter] &gt;&gt;&gt; 1); key64[counter] = (byte) (key64[counter] &lt;&lt; 1); } for (int counter = 0; counter &lt; KEY_LENGTH - 1; counter++) { key56[counter] = (byte) (key64[counter] &lt;&lt; counter); key56[counter] = (byte) (key56[counter] | (key64[counter + 1] &gt;&gt;&gt; (KEY_LENGTH - 1 - counter))); } /*Conversion from 64 to 56 bit testing code System.out.println(new String(key56)); System.out.println(); for (int counter1 = 0; counter1 &lt; 7; counter1++) { for (int counter2 = 7; counter2 &gt;= 0; counter2--) { System.out.println(key56[counter1] &amp; (1 &lt;&lt; counter2)); } System.out.println(); }*/ } catch (IOException e) { e.printStackTrace(); } } </code></pre>
 

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