Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XOR mask in java android

User enter code word and text to encrypt and program should put XOR mask - code on text - and turn back to normal , but it just put on mask and dont turn back to normal look , 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 
like image 902
ilbets Avatar asked Dec 15 '25 20:12

ilbets


1 Answers

You output the address of the array. You want the content. Arrays have not useful toString() mwthod.

change

rezult=Ctext.toString();

to

rezult=new String(Ctext);

same for

rezult+=Ctext.toString();

=>

rezult+=new String(Ctext);
like image 198
MrSmith42 Avatar answered Dec 17 '25 10:12

MrSmith42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!