Queries and Questions

I recently started posting unresolved issues on stack overflow

I have written this code to generate the bit stream corresponding to string a and then invert specific bits in a bit stream.the variable cc gets an integer value in the processing before the code snippet.

However it gives Array Index Out Of Bounds Exception on the following line.

if(sb2.charAt(cc)=='1')

can anyone tell me what is the probable cause?

package abc1;import java.util.Scanner;publicclass abc2 {publicstaticvoid main(String s[]){String seckey=" ";String cbs=" ";String a ="Manikaparasher";System.out.println("String originally:"+ a);char[] car= a.toCharArray();StringBuilder sb=newStringBuilder();for(char c:car){
cbs=Integer.toBinaryString((int)c);
sb.append(cbs);}Scanner sc=newScanner(System.in);System.out.println(" Enter your passkey ");int n=sc.nextInt();int ul, ll;double nv1,nv2,ns;
ll= n*3;
ul= n*7;
nv1=ll+(Math.random()*(ul-ll));
nv2=ll+(Math.random()*(ul-ll));int nv11=(int)nv1%7;//inversion bitint nv22=(int)nv2%3;//embedding bit
ns=ll+(Math.random()*(ul-ll));int ns1=(int)ns%5;//start bitif(nv11==nv22){
 nv11++;}if(nv22==ns){
ns++;}if(nv11==ns){
nv11++;}

seckey="I"+nv11+"E"+nv22+"S"+ns1;System.out.println(seckey);System.out.println("old"+ sb.toString());System.out.println("nv11"+ nv11);StringBuilder sb2=newStringBuilder(sb);int cc=0;while(!cbs.isEmpty()){
cc=cc+nv11;if(sb2.charAt(cc)=='1'){
sb2.setCharAt(cc,'0');
sb2.append(sb);}else{
sb2.setCharAt(cc,'1');
sb2.append(sb);}

}

System.out.println("new"+ sb2.toString());}}
Advertisements

Constructive and genuine appreciation and/or criticism most welcome

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s