Caesar cipher code app for android -
my question how can code 'space' empty space in coded text , because if enter text example abc'space'abc coded letters abc , instead of space # want empty space...and decode, reverse function if press space 7 want empty space..i don't want code space or decode him that's idea
public class mainactivity extends actionbaractivity { textview mytext, mytext2; button mycodebutton, mydecodebutton, deletebutton; public static edittext enterededittext; public string gettext; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mytext = (textview) findviewbyid(r.id.textview1); mytext2 = (textview) findviewbyid(r.id.textview2); enterededittext = (edittext) findviewbyid(r.id.edittext1); mycodebutton = (button) findviewbyid(r.id.button1); mydecodebutton = (button) findviewbyid(r.id.button2); deletebutton = (button) findviewbyid(r.id.button3); code_my_textbutton(); decode_my_textbutton(); // clearing edit_texts , text_views deleteclick(); } public void code_my_textbutton() { mycodebutton.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { caesar_cipher_coding_method(); mytext2.settext(""); } }); } private void caesar_cipher_coding_method() { int shift = 3; editable msg = enterededittext.gettext(); string s = ""; int len = msg.length(); (int x = 0; x < len; x++) { char c = (char) (msg.charat(x) + shift); if (c > 'z' || (c > 'z' && c < 'd')) { c -= 26; } s += c; } mytext.settext(s); } public void decode_my_textbutton() { mydecodebutton.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { reverse_caesar_cipher_coding_method(); } }); } private void reverse_caesar_cipher_coding_method() { int shift = -3; editable msg = enterededittext.gettext(); string s = ""; int len = msg.length(); (int x = 0; x < len; x++) { char c = (char) (msg.charat(x) + shift); if (c < 'a' || (c < 'a' && c > 'w')) c += 26; s += c; } mytext2.settext(s); mytext.settext(""); } // clearing edit_texts , text_views public void deleteclick() { deletebutton.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { enterededittext.settext(""); mytext.settext(""); mytext2.settext(""); } }); } }
all have check in both loops so:
for (int x = 0; x < len; x++) { if (character.iswhitespace(msg.charat(x))) { s += " "; continue; } char c = (char) (msg.charat(x) + 3); if (c > 'z' || (c > 'z' && c < 'd')) { c -= 26; } s += c; }
Comments
Post a Comment