# I am having issues to run this code ?

• 06-23-2012, 10:19 PM
dantzig
I am having issues to run this code ?
the idea is we want generate the Key stream for encryption and decryption, we will process with the following steps
21 24 2 5 9 15 18 1 16 12 27 4 10 19 7 20 23 26 13 3 28 25 22 8 6 14 11 17

Step 1: Swap the A joker (27) with the card following it. Thus, we swap 27 and 4.

21 24 2 5 9 15 18 1 16 12 4 27 10 19 7 20 23 26 13 3 28 25 22 8 6 14 11 17

Step 2: Move the B joker (28) down two places.

21 24 2 5 9 15 18 1 16 12 4 27 10 19 7 20 23 26 13 3 25 22 28 8 6 14 11 17

Step 3: Do the triple cut. Everything above the first joker (27, in this case) goes to the bottom of the deck. Everything below the second joker (28) goes to the top.

8 6 14 11 17 27 10 19 7 20 23 26 13 3 25 22 28 21 24 2 5 9 15 18 1 16 12 4

Step 4: The value of the bottom card is 4, so we take the first four cards of the deck and place them right before the 4.

17 27 10 19 7 20 23 26 13 3 25 22 28 21 24 2 5 9 15 18 1 16 12 8 6 14 11 4

Step 5: The top card is 17. So the keystream value is the 18th card, i.e., 9.
Thank you.

public class Deck {

public Deck(int[] deck)
{
Set s = new HashSet();
for (int i = 1; i<29 ; i++)
{
}
for (int i = 0 ; i<deck.length ; i++)
{
if (!s.contains(deck[i]));
System.out.println("The deck doesn't contains the integers from 1 to 28");

}
}

{
int[] array = new int[deck.size()];
for(int i = 0;i < array.length;i++)
array[i] = deck.get(i);
return array;
}
}

int[] b = toIntArray(deck);
for (int i = 0 ; i<b.length ;i++)
{
if (b[i]== 27)
{
int temp = b[i];
b[i]=b[i+1] ;
b[i] = temp ;

}
}
int[]c = b ;
for (int i = 0 ; i <c.length ; i++)
{
if (c[i] == 28)
{
int temp1 = c[i];
c[i]= c[i+1];
c[i]= temp1 ;
int temp2 = c[i+1] ;
c[i+1]=c[i+2];
c[i+2]= temp2 ;

}

}

int pos = 0 ;
int[] temp = new int[deck.size()] ;

if (deck.indexOf(27) <deck.indexOf(28) ){

// copy back to the front of middle
for (int i = deck.indexOf(28)+1 ; i<deck.size() ;i++){
temp[pos]= deck.get(i) ;
pos++ ;
}
// copy middle section to the middle of temp
for (int i =deck.indexOf(27); i<deck.indexOf(28) ; i++){
temp[pos]=deck.get(i);

}
// Copy first section to temp array
for (int i = 0; i < deck.indexOf(27); i++)
{
temp[pos] = deck.get(i);
pos++;
}
//Copy temp array back to original array
for (pos = 0; pos <deck.size(); pos++)
{
deck.set(pos, temp[pos]);
}

}
//if the joker 28 is after 27 in the deck
else{
// copy back to the front of middle
for (int i = deck.indexOf(27)+1 ; i<deck.size() ;i++){
temp[pos]= deck.get(i) ;
pos++ ;
}
// copy middle section to the middle of temp
for (int i =deck.indexOf(28); i<deck.indexOf(27) ; i++){
temp[pos]=deck.get(i);

}
// Copy first section to temp array
for (int i = 0; i < deck.indexOf(28); i++)
{
temp[pos] = deck.get(i);
pos++;
}
//Copy temp array back to original array
for (pos = 0; pos <deck.size(); pos++)
{
deck.set(pos, temp[pos]);

}
int t1 = deck.get(0);
int t2 = deck.get(1);
int t3 = deck.get(2);
int t4 = deck.get(3);

for (int i = 4 ; i<deck.size()-1 ; i++){
deck.set(i-4, deck.get(i)) ;
}
deck.set(23, t1);
deck.set(24, t2);
deck.set(25, t3);
deck.set(26, t4);
}

return deck;
}

public int getKeystreamValue(){
int x = deck.get(0) + 1 ;
return deck.get(x);
}
}
• 06-23-2012, 10:25 PM
Fubarable
Re: I am having issues to run this code ?
OK, you've posted your assignment, you've posted some unformatted code, and have mentioned that you are having "issues" but I think that for us to be able to help you, you need to tell us more.

• First and foremost, tell us the details of the problems you're having.
• If the code doesn't compile, please post any and all error messages, and indicate which lines in the code are the source of these errors.
• Likewise for any runtime exceptions -- please post the full exception stacktrace and indicate which lines are causing the errors.
• Consider editing your post above and adding [code] [/code] tags around your pasted code so that it will retain its formatting and be easier to read.

Best of luck and welcome to the java-forums. org!
• 06-23-2012, 10:33 PM
dantzig
Re: I am having issues to run this code ?
Thank you.
Let me send it again with the main method.
• 06-23-2012, 10:47 PM
dantzig
Re: I am having issues to run this code ?
That is the error
Exception in thread "main" java.lang.ClassCastException: [I cannot be cast to java.lang.Integer
at WhitespaceString.tripleCut(WhitespaceString.java:1 39)
at WhitespaceString.main(WhitespaceString.java:52)

import java.util.Arrays;
import java.util.Iterator;
import java.util.Scanner;
import java.io.File;
import java.lang.String;

public class WhitespaceString{
private static int[] c;

public static void main(String[] args){

//21 24 2 5 9 15 18 1 16 12 27 4 10 19 7 20 23 26
// 13 3 28 25 22 8 6 14 11 17

int []a = toIntArray(deck) ;
int x = getKeystreamValue();
System.out.println("The value of key stream is"+ x);
for (int i = 0 ; i<l.size() ; i++){
System.out.println(l.get(i));
}

}

int[] array = new int[deck.size()];
for(int i = 0;i < array.length;i++){
array[i] = deck.get(i);
System.out.println(array[i]) ;

}
return array;
}

int[] b = toIntArray(deck);
for (int i = 0 ; i<b.length ;i++)
{
if (b[i]== 27)
{
int temp = b[i];
b[i]=b[i+1] ;
b[i] = temp ;

}
}
int[]c = b ;
for (int i = 0 ; i <c.length ; i++)
{
if (c[i] == 28)
{
int temp1 = c[i];
c[i]= c[i+1];
c[i]= temp1 ;
int temp2 = c[i+1] ;
c[i+1]=c[i+2];
c[i+2]= temp2 ;

}

}

int pos = 0 ;
int[] temp = new int[deck.size()] ;

if (deck.indexOf(27) <deck.indexOf(28) ){

// copy back to the front of middle
for (int i = deck.indexOf(28)+1 ; i<deck.size() ;i++){
temp[pos]= deck.get(i) ;
pos++ ;
}
// copy middle section to the middle of temp
for (int i =deck.indexOf(27); i<deck.indexOf(28) ; i++){
temp[pos]=deck.get(i);

}
// Copy first section to temp array
for (int i = 0; i < deck.indexOf(27); i++)
{
temp[pos] = deck.get(i);
pos++;
}
//Copy temp array back to original array
for (pos = 0; pos <deck.size(); pos++)
{
deck.set(pos, temp[pos]);
}

}
//if the joker 28 is after 27 in the deck
else{
// copy back to the front of middle
for (int i = deck.indexOf(27)+1 ; i<deck.size() ;i++){
temp[pos]= deck.get(i) ;
pos++ ;
}
// copy middle section to the middle of temp
for (int i =deck.indexOf(28); i<deck.indexOf(27) ; i++){
temp[pos]=deck.get(i);

}
// Copy first section to temp array
for (int i = 0; i < deck.indexOf(28); i++)
{
temp[pos] = deck.get(i);
pos++;
}
//Copy temp array back to original array
for (pos = 0; pos <deck.size(); pos++)
{
deck.set(pos, temp[pos]);

}
int t1 = deck.get(0);
int t2 = deck.get(1);
int t3 = deck.get(2);
int t4 = deck.get(3);

for (int i = 4 ; i<deck.size()-1 ; i++){
deck.set(i-4, deck.get(i)) ;
}
deck.set(23, t1);
deck.set(24, t2);
deck.set(25, t3);
deck.set(26, t4);
}

return deck;
}

public static int getKeystreamValue(){
int x = deck.get(0) + 1 ;
return deck.get(x);
}

}
• 06-23-2012, 11:14 PM
Fubarable
Re: I am having issues to run this code ?
Again, please edit your post above and add the code tags as described in my first post. Please indicate which line is causing the exception, again as I have requested previously.
• 06-24-2012, 01:53 AM
Ronin
Re: I am having issues to run this code ?
dantzig,

As I have free time and want the refresher, I have taken the liberty of debugging your program. There are multiple errors within your code but you can address these one at a time. The first issue is to get your code to compile.

Comment out or remove the code below and take it from there.
Code:

`deck = new LinkedList(Arrays.asList(c));`
Regards.