XOR mask in java android
The user enters a codeword and text for encryption, and the program should put the XOR mask-code in the text - and return to the normal state, but it just overlaps the mask and does not return to normal, why?
public void onClick(View arg0) {
code = etCode.getText().toString();
text = etText.getText().toString();
while(code.length()<text.length()){
code+=code;
}
char[] Ccode = code.toCharArray();
char[] Ctext = text.toCharArray();
for(i=0;i<Ctext.length;i++){
Ctext[i]^=Ccode[i];
}
rezult=Ctext.toString();
for(i=0;i<Ctext.length;i++){
Ctext[i]^=Ccode[i];
}
rezult+="\n";
rezult+=Ctext.toString();
tvMain.setText(rezult);
}
});
if i enter code : code , text : text
it shows:
[C@40527808 [C@40527808
+3
source to share
3 answers
In Java toString()
, the default operation on arrays is the conversion to the internal identifier you see. Try using:
rezult = new String(Ctext);
...
rezult += new String(Ctext);
or, depending on what you want to display (since it's not clear to me what the Ctext
displayed characters always contain):
rezult = Arrays.toString(Ctext); ... rezult += Arrays.toString(Ctext);
This will give you a comma-separated array of character values surrounded by square brackets.
0
source to share