简体   繁体   中英

struggling in integer string conversion

ok this my first question here i hope i well learn something .so basically i have this project of encryption and decryption the hard part is to convert string to int so i can preform some logic operation on them then represent them back to string(encrypted text) then convert string(encrypted text) back to integers and reverse the opration and convert the result to decrypted message`

System.out.println("enter the statment you wish to encode");
String plaintext=sc.nextLine();
int [] a=new int[plaintext.length()+1];

for ( int i = 0; i < plaintext.length(); ++i ) {
    char c = plaintext.charAt( i );
    int ascii = (int) c;
    System.out.print(ascii); 
    a[i]=ascii;
}

System.out.println("||||");
for(int i=0; i<plaintext.length(); i++){
    System.out.print(a[i]^6 ); 
}

System.out.println("||||");
String str = Arrays.toString(a);
System.out.println("str.."+str);

/*for ( int c = 0; c <plaintext.length(); ++c) {

char pointer=a.charAt();
}

I know it is a mess so basically i convert string into int[] but how i can convert back the int[] to string?? chatAt()wont work so what is the solution string array meby??

System.out.println("enter the statment you wish to encode");

String plaintext=sc.nextLine();
int [] a=new int[plaintext.length()];
for ( int i = 0; i < plaintext.length(); i++) {
   char c = plaintext.charAt(i);
   int ascii = (int) c;
   System.out.print(ascii); 
   a[i]=ascii;
}
System.out.println("||||");

for(int i=0; i<plaintext.length(); i++){
    System.out.print(a[i]^6 ); 
}
System.out.println("||||");

String str = Arrays.toString(a);
System.out.println("str.."+str);

String str2 = "";
for ( int c = 0; c < a.length(); c++) {
    str2 += (char)a[c];
}

System.out.println("str2.."+str2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM