Encryption Algorithm Question
in
Programming Questions
•
11 months ago
Hey all,
andrewgies17
I cannot figure out what the problem is with this program. I want to, for each of the characters in the input, obtain the appropriate replacement, and fill a second char array with the results. This is what I have, and the highlighted line returns a NullPointerException.
- char ec[][] = {{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'},
- {'O', 'N', 'E', 'W', 'R', 'D', 'S', 'T', 'Y', 'A', 'B', 'C', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'P', 'Q', 'U', 'V', 'X', 'Z'}};
- String input = "ANDREW";
- String encryption;
- char[] tempChars = input.toCharArray();
- char[] afterChange;
- void setup() {
- println(ec[0][0]);
- println(ec[1][0]);
- for(int pos = 0; pos < tempChars.length; pos++) {
- for(int scroll = 0; scroll < 26; scroll++) {
- if(tempChars[pos] == ec[0][scroll]) {
- afterChange = append(afterChange, ec[1][scroll]);
- } else {
- }
- }
- }
- encryption = afterChange.toString();
- println(encryption);
- }
- void draw() {
- }
andrewgies17
1