//Sixth grade shift cipher code - lower case encryption code //for students to encrypt messages //original setting - 13 and letter swaps disbled void setup() { size(800, 400); } //write out the message void draw() { int shift; //TO DO - set the shift based on instructions shift = 13; background(255); textSize(24); fill(0); text(cipher("we are hidden", shift), 10, 30); //should read: jr ner uvqqra } //shift the characters by the specified amounts //leave spaces as spaces //and two possible letter swaps String cipher(String msg, int shift) { char firstSwap, firstRes; char secondSwap, secondRes; boolean swapOne = false; boolean swapTwo = false; //TO DO - set the swaps based on instructions! firstSwap = 'a'; firstRes = 'c'; secondSwap = 'r'; secondRes = 'n'; String s = ""; int len = msg.length(); for (int x = 0; x < len; x++) { char Curc = (char)msg.charAt(x); if (Curc != ' ') { if (swapOne) { if (Curc == firstSwap) { Curc = firstRes; } else if (Curc == firstRes) { Curc = firstSwap; } } if (swapTwo) { if (Curc == secondSwap) { Curc = secondRes; } else if (Curc == secondRes) { Curc = secondSwap; } } char c = (char)(Curc + shift); if (c > 'z') s += (char)(Curc - (26-shift)); else s += (char)(Curc + shift); } else s += (char)(msg.charAt(x)); } return s; }