简体   繁体   English

努力进行整数字符串转换

[英]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` 好吧,这是我的第一个问题,我希望我能学到一些东西。所以基本上我有这个加密和解密的项目,最困难的部分是将字符串转换为int,这样我就可以对它们进行一些逻辑运算,然后将它们表示回字符串(加密文本),然后将字符串(加密的文本)转换回整数并反转运算,然后将结果转换为解密的消息。

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?? 我知道那是一团糟,所以基本上我将字符串转换为int[]但是如何将int[]转换回字符串? chatAt()wont work so what is the solution string array meby?? chatAt()无法正常工作,所以解决方案字符串数组是什么?

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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