A variant on the ENIGMA machine encryption works well in a single loop, and is sufficiently complex to give students a real challenge.
The core idea of the ENIGMA machine for this assignment is that (1) a number is given as an initial key, and (2) every prior letter used influences how the next letter will be encrypted.
So, use a modular circle of encryptable characters (I chose ASCII 32 (
) to 126 (~
), and just like a Caesar cipher, take your first letter and move it over by the key
values. But now modify key
itself by adding the ASCII value of the inputted letter that you just encrypted to it.
Unstated in that description is the idea of creating a modular circle that doesn't begin from 0. This is a pretty complex idea for students at this level to work with, and it helps to give them some guidance in this department.
Following this formula with the initial key 16
, the statement
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
Should get you:
Vf|0Pdhx,2RTch)=CZ`o0JPRey:<DTt%;Nnuw-6<Oc$':J`hq'GN^q'0P`o0ENXl-1APeo~%4Iu68Xgm&FUWlv'6b#'7FJPZqw|=GVvcmpv*?Y&FHW\|"(-7;=RX]}3Ccx"(HYl|.>R\q{,;[py{1QS`m.<BQqs'-MQdjl"(-MSe{}+Y
Ask students to similarly create a decrypt method, but offer far less guidance than you did for encrypt. It will require them to make sense of all of the mathematical operations that they performed in encrypt in order to successfully undo it.
You can also provide them with a few mystery strings to uncover. The first student who successfully follows the directions given by the mystery strings gets some sort of prize or extra credit. (The mystery strings themselves explain this; no need to give the secret away in advance.)