Technical 00: Learning to Program Like It's 1985

Programming

In each technical homework, you will be given well-defined programming and/or digital artifact analysis tasks that involve the use of vintage technologies that have had a major impact on today’s technology. Technical homeworks are designed to be accessible to students from any discipline, with requisite knowledge being provided to you in class and/or in the assignment in advance of the due date. These assignments are usually due by 5pm on Tuesdays of the following week they are assigned. This technical homework is due on 1/30 at 5pm.

Logo Programming

 

 

Picture yourself as a kid in the 1980s. There's this new thing called the personal computer that all of your friends are jazzed up about. And you want to get in on the action. After much pleading, your parents finally break down and get you a Commodore 64. You play some games. You get a sense of how the computer works. But you want to learn more because the possibilities of this machine seem endless. Now it's time for you to figure out the basic elements of computer programming.

Lucky for you, some prominent computer scientists with an interest in computer science education anticipated kids like you way back in the 1960s. Wally FeurzeigSeymour Papert, and Cynthia Solomon created the Logo Programming Language as a simple instructional tool to introduce students to programming. Importantly, Logo is visual. The language controls a "Turtle" (i.e., a cursor) on the screen that draws shapes based on various programming language instructions. The programmer is immediately able to see the effect of a new instruction on the screen, making debugging rather easy. 

The language's design is also rather simple, meaning there aren't many instructions to learn. Here is the basic list of logo instructions to control the turtle:

Instruction Short Purpose Instruction Example (if arguments needed)
forward fd Move the turtle forward forward 50
right rt Rotate the turtle right right 90
left lt Rotate the turtle left left 90
repeat - Repeat a set of instructions repeat 4 [fd 50 rt 90]
penup pu Stop drawing  
pendown pd Start drawing  
penerase pe Turn the turtle into an eraser  
clearscreen cs Clear a drawing  
home - Put the turtle in its home position  

There are other instructions, depending on the implementation of the turtle being used. For this assignment, we will use the following web-based Logo interpreter: https://www.calormen.com/jslogo/. Code is written in the lower box, while the output is shown in the upper box with the turtle. On the right-hand panel, you can find a language reference, as well as code samples that will be useful to you as you work on this assignment.

To begin, let's draw a square. This can be done in one line using 'repeat 4 [fd 50 rt 90]'. You can think of the 'repeat' instruction as something of a loop, which repeats the code within the brackets some number of times. The 'fd' instruction draws a line, while the 'rt' instruction changes the angle of the turtle. The output will look like this:

Turtle6

More elaborate shapes can be drawn just by adjusting the angle and length of the lines, as well as the number of repetitions. For instance, 'repeat 5 [fd 161.8 lt 144]' draws a star:

Turtle2

Now that you've seen these examples, let's get down to some coding.

Coding Challenge #1: Draw the letters ND using a Logo program. 

Write a Logo program that will draw the letters ND on the screen. Your output should look approximately like this:

Turtle4

Make sure to save your code for later (see the submission instructions below).

Coding Challenge #2: Draw something creative of your own choosing using a Logo program.

Recall the following tenet of the Hacker Ethic: You can create art and beauty on a computer! Come up with a cool design to draw and figure out how to program it using Logo. We'll show off some of the best designs in class, and we might even award some extra credit for particularly elaborate drawings.

BASIC Programming

Having cut your teeth on Logo, it's time to move on to a more general purpose programming language. BASIC (Beginners' All-purpose Symbolic Instruction Code) is another programming language designed to teach beginners how to program. It was designed by John G. Kemeny and Thomas E. Kurtz in 1963. Unlike Logo, it can be used for any general purpose computing task. That said, it's also useful for drawing. So let's begin there. 

BASIC has a much more extensive set of instructions, but we only need a few to replicate the type of drawing we were doing in Logo. Importantly, BASIC has more sophisticated constructs like variables and proper multi-line loops. Here is a set of instructions that are useful for drawing:

Instruction Purpose Instruction Example (if arguments needed)
CLS Clear the screen  
PRINT Print text on the screen PRINT "Hello World"
LET Assign a variable LET X = 42
FOR Loop over a range of numbers FOR F = 0 TO 10
NEXT Iterate through a range of numbers NEXT F
PLOT Plot a point X,Y that is a color C PLOT 1, 1, "green"
SIN Sine function SIN(1)
COS Cosine function COS(1)
REM Define a subroutine REM Subroutine
RETURN Return out of a subroutine  
GOSUB Jump to a subroutine at a line number GOSUB 5000
END Terminate the program  

For the next set of coding challenges, we will use the following web-based BASIC interpreter: http://www.quitebasic.com/. The interface of this interpreter is very similar to the Logo interpreter we used, with code being typed into the box on the left, drawings shown in the box in the upper-right, and text output in the box in the lower-right. Also in the upper-right box, you can find a language reference, as well as code samples that will be useful to you as you work on this assignment.

Here's an example of a program to draw a line. It uses the PLOT instruction to tell the BASIC interpreter to change the color of a square on the grid. The FOR loop is used to sequential mark five different squares (the loop starts counting with 0). Note the line numbers that begin each line of code. In BASIC, these are important because the language supports jumping to different lines across a program. Make sure to include line numbers as you code your own basic programs. 

2000 CLS
2010 PRINT "Let's draw a line"
2020 PRINT
2110 LET X = 0
2120 LET Y = 0
2130 LET N = 4
2140 LET C = "green"
2150 FOR F = 0 TO N
2160 PLOT X+F,  Y,  C
2170 NEXT F

The output of this program is the following, a small line segment at the very bottom of the grid:

Basic1

Next, let's draw a rectangle using the same set of instructions that we used to draw the line, plus a couple of subroutines to demonstrate the principle of code re-use: 

2000 CLS
2010 PRINT "Drawing a rectangle..."
2020 PRINT
2030 LET X = 15
2040 LET Y = 25
2050 LET N = 8
2060 LET C = "green"
2070 GOSUB 5000
2080 LET X = 15
2090 LET Y = 33
2100 LET N = 16
2110 GOSUB 6000
2120 LET X = 31
2130 LET Y = 25
2140 LET N = 8
2150 GOSUB 5000
2160 LET X = 15
2170 LET Y = 25
2180 LET N = 16
2190 GOSUB 6000
2200 END
5000 REM Subroutine1 -- draw a vertical line
5010 FOR F = 0 TO N
5030 PLOT X,  Y + F,  C
5040 NEXT F
5050 RETURN
6000 REM Subroutine2 -- draw a horizontal line
5010 FOR F = 0 TO N
6020 PLOT X + F,  Y ,  C
6030 NEXT F
6040 RETURN

The output of this program is the following:

Basic2

Coding Challenge #3: Port your Logo program to draw ND to BASIC.

One of the best ways to learn a new programming language is to port a program from one language you know into the new language. In this coding challenge, once again draw ND, but do it with BASIC code. Your output should look approximately like this:

Basic3

  

Coding Challenge #4: Draw something creative of your own choosing using a BASIC program.

Come up with a cool design to draw and figure out how to program it using BASIC. You could port your original Logo drawing from Challenge #2, or do something new. Again, we'll show off some of the best designs in class, and we might even award some extra credit for particularly elaborate drawings.

Bourne Shell Programming

So you've gotten a lot better at programming, and now you're moving beyond the friendly world of personal computing. The local university has a fairly liberal user policy for its computer labs, and you've managed to score access to a UNIX network. The system administrator (sysadmin) is sympathetic to your quest for computing knowledge, but only lets you use the network late at night with a restricted account. You are now learning the UNIX operating system. UNIX is powerful, in that it provides a rich set of software tools in the form of command line programs. Using a shell interpreter (i.e., an interactive command environment), these commands can be strung together into scripts that can be used to automate different tasks.

One of the oldest shells still in use is the Bourne Shell. It was developed by  Stephen Bourne at Bell Labs in the 1970s. For this last coding challenge, we'll use the following web-based interpreter: https://rextester.com/l/bash_online_compiler. A handy beginner's guide to shell programming is here.

Coding Challenge #5: Write some scaffolding for a password cracking program using a Bourne Shell Script.

This loop thing you learned from Logo and BASIC might be useful to solve other problems you think. One problem on your mind is gaining access to a less restricted network account. You've learned recently that sysadmins can be lazy, and often choose a common password. From some underground hacker manuals you've been reading, you know that the following set of passwords are very common: root, god, password, admin, operator, debug. Of course, you don't want to spend time entering these passwords in by hand to find out if you can compromise a sysadmin's account --- especially as the list grows. Wouldn't it be great to automate the task of password cracking?

Browsing documentation on shell programming, you think the following instructions will be handy:

Instruction Purpose Instruction Example (if arguments needed)
X = () Define an array X = ("foo" "bar")
for Loop over some data for Y in ${X[@]};
do Execute some command in a loop do echo $Y
done End loop block  
echo Echo text to the terminal echo "foo"

Using the above instructions, write a small shell script that loops through the list of common passwords above and prints them to the terminal. This will serve as a scaffold for a password cracker later on as you figure out more advanced UNIX input/output processing. You don't know everything yet, after all, you're just a kid...

Grading

You must submit source code for all five of the coding challenges in this assignment. Each coding challenge is worth 10 points, and will be graded in terms of the following criteria:

  • Is the program functional? Does it run without any errors or warnings?
  • Does the output of the program match the expected output for Challenge 1, 3 and 5?
  • Is the output for Challenge 2 and 4 creative?

Submission Instructions

  • Place your source code for each of the five questions into a plaintext file that will be saved in the Google drive folder that you previously shared with our TA Ellen for the first writing reflection

  • Name your plaintext file using this convention: lastname_firstname_duedate. Example: Joyce_Ellen_013024.txt

  • Ellen will collect each assignment directly from your drive after it is due