back to the Compass Rose

Computer Science 2
Assignment 4 -- Exploring Text Processing cont'd.: Codes and Ciphers

In this assignment you will investigate the commands and procedures in Logo that allow a programmer to process text so as to create encoded sentences from what the user inputs and to decipher coded input from the user. You will use the techniques of parsing and building words and sentences, but you will also develop algorithms using modular arithmetic to act as cipher engines. As in the past you will create complex programs from smaller independent modules employing the techniques of top-down design.


  1. Review the following Logo primitive commands:
    1. FIRST
    2. LAST
    3. BUTFIRST
    4. BUTLAST
    5. WORD
    6. SENTENCE
  2. Find the ASCII values for the upper and lower case alphabet and the period, questionmark, and space characters. What is ASCII, anyway?
  3. Learn about these commands.
    1. REMAINDER
    2. ASCII
    3. CHAR
  4. Learn about "Shift Ciphers."
  5. Develop algorithms for "shifting" an input letter up or down the alphabet by a given number of letters and wrapping around to the beginning again if the shift puts letter's ASCII value beyond the end of the alphabet.
  6. Create Logo procedures that will prompt the user to enter a string of text and process it in the following ways then output the results to the screen:
    1. Get a "shift value" for the cipher.
    2. Translate each word in the sentence into its encoded equivalent using the shift value.
    3. Build a new encoded sentence and output it to the screen.
  7. Develop algorithms for reversing this process; i.e. , translate encoded text into plain text again, and output the results to the screen:
    1. Take in an shift encoded sentence.
    2. Translate it by trying every possible shift value.
    3. Print out all these possibilities on the screen so the user can determine the correct encoding.
  8. Develop an algorithm for translating a string of plain English text input by the user into an encoded sentence using one of the other cipher schemes described in the resources below.
  9. Develop and debug a program that will implement your algorithm having the following features:
    1. Gets input from the user for the sentence to be translated.
    2. Translates the input sentence according to the rules for your encoding.
    3. Displays on the screen both the plain English and encoded sentences.

Modular Arithmetic Links

Modular Arithmetic
This article discusses the basis for modular arithmetic at Cut_the_Knot.org
A Discussion of Clocks and Modular Arithmetic
This page is similar in form to the one on shift cyphers from the Shodor Foundation above. It is a brief clear exploration of the topic.
Modular Arithmetic from Math Alive
This page explains how modular arithmetic is applied in the important computer-based encryption scheme called RSA cryptography. It shows how a program cna be constructed to carry out encryption and decoding.

Ciphers and Cryptography

The Natonal Security Agency's Cryptologic Museum
Go here to tour the various exhibits detailing the various ways the NSA and other agencies have been involved in cryptography through the history of the U.S.
Cryptography A-Z
This site from a Finnish Communications Security firm provides a complete course in cryptography and cryptographic algorithms
The Numeroscope
Paul Burchard's Numeroscope discusses not just codes and ciphers but the basic math behind them. Especially useful is his discussion of "Clock Numbers" another way of looking at modular arithmetic.
Cryptology Lessons from Ken Dunham
Here Ken goes all the way from the binary number system to the history of computers to a lessons about all sorts of ciphers and codes. this content is directed at secondary students and is very accsessible for reading and exploration.
The Black Chamber a site devoted to cryptography by Simon Singh
Definitions and background about cryptography and codes
Caesar's Shift Cipher: An example of a substitution cipher
Cryptography and Ciphers Discussion
This page offers a fairly complete introduction to using the shift cipher and its relationship to Modular Arithmetic.


Last updated Tuesday, April , 2005
© 2000-05 All rights reserved   Tom Stork