|
Cryptography - Part I: Basic C++
Phase I: Editing and Compiling
Phase II: Understanding C++
Phase III: Beginning Programming
Phase I: Editing and Compiling
This phase of the project is intended to introduce the participant to
the basic C++ programming environment on the Challenge servers.
Note: Helpful (but not necessary) instructions are in italics.
-
1. Log onto mode.lanl.k12.nm.us.
1a. In your root directory, make a directory for this project with the following command:
mkdir project
Feel free to replace a more descriptive name for "project".
1b. Go into the project directory (cd project), and create subfolders for this part and phase of the project:
mkdir part_one
mkdir part_one/phase_one
Once more, feel free to replace the directory names with something more descriptive.
1c. Go to the directory that is intended for this phase of the project:
cd part_one/phase_one
-
2. Obtain the source code, slant.c for this phase - print it out.
-
3. Open an editor for entering the source code:
pico slant.c
-
4. Enter the source code.
4a. It is possible to just "cut and paste" the source. It is not advisable to do so. Entering in this initial code by hand will give the participant a sense of grammar and feel of the C++ language. This small extra effort will pay off in later exercises. Also, "cut and paste" can mangle the source code if not done properly.
-
5. After entering the code, exit
pico using the <Ctrl-X> command.
Say "Y" to the "Save modified
buffer" prompt.
-
6. List the contents of the current working directory (ls). Be sure that slant.c appears. If slant.c does not appear, go back to step 3 and continue.
6a. We will be using the g++ compiler. View the manual page for the g++ compiler:
man g++
Read the manual. Don't worry if it is mostly foreign to you. Pay attention to the -o option.
-
7. Compile slant.c:
g++ slant.c
7a. Compile slant.c using the -o option:
g++ slant.c -o slant.x
Feel free to change slant.x to something more descriptive.
If compiler errors appear, the source code was not entered correctly. If this is the case, remove the source code (rm slant.c) and go back to step 3.
If compiler errors appear, the source code was not entered correctly. If this is the case, remove the source code (rm slant.c) and go back to step 3.
-
8. Run the program:
./a.out
or if you used -o:
./slant.x
Enter in some cleartext and an integer key to have the program output the encrypted text.
-
9. Run the program and encrypt the phrase "supercomputing is cool" (no quotes) with a key of 4.
-
10. Submit the encrypted text
to obtain the source code "unslant.c" for the next phase.
Phase II - Understanding C++
Congratulations on finishing the previous milestone. Not challenging
enough? Well, here's something that should keep you busy for a while...
The objective of this milestone is to get you thinking about the various
parts of C++ code: variables, functions, arrays, and comments. You will be
given a C++ program for decoding the enciphered text that was generated in
the previous phase. The code looks daunting, but with extensive and
creative analysis of the code, you should be able to advance to the next
step.
Note: Helpful (but not necessary) instructions are in italics.
-
1. Obtain the source code for Phase II, and name this code "unslant.c".
Either copy and paste it over, or edit it in by hand.
-
2. Put the source code that you
received in a directory for this
part of the phase. If you don't
remember how to make directories,
refer to the
Phase I instructions.
-
3. Open unslant.c in a text editor.
Pico or Vi will suffice.
-
4. Determine what the code does and
how.
-
5. You will be tested on
how well you understand the code
in unslant.c, and whether or not you can correctly execute the code.
Pass this test to receive the source code
for phase III.
Hints
1. Don't try to do the code in one complete analysis. Break up the code
by functions and loops, then assign each team member a piece of code to
analyze.
2. If you understand a function or other piece of code, comment it. Put in
comments into the code so that others looking at your work will understand
what's going on.
3. This is not a closed book affair. Use books, the Internet, and other
resources to help you in this task. If you already understand all of this
without looking up anything, you should not be in this Challenge category.
4. This is difficult stuff. If you find yourself going nuts, take a break.
Many things do not become apparent on the first look.
5. If you are questioning what the code does, compile it and compare the
program running with the source.
Phase III - Basic Programming
In this phase, you will finally begin to start some coding. A variety of
basic C++ operations will be required, so be sure that you are familiar
with the following before starting:
1. Input / Output
2. Data Types (char and int in particular)
3. Arrays
4. Conditional Statements (x = = 9)
5. Loops (if, while, for)
The source code you will receive is mostly incomplete. It is your task to
complete the source so that it operates as directed.
The program in question is a tool that will assist in later
crypto-analyses. It will read in a string of ASCII text and report a
number of properties about the string:
1. Number of occurrences of each character
2. Length of string
3. Number of unique characters
- 1. Obtain the source code for Phase III, and name this code "alpha-analyze.c".
Either copy and paste it over, or edit it in by hand.
- 2. Open the source code in a text
editor. You will see the beginning and
end of the source, but the body is
largely missing.
- 3. Implement the functions that are
contained in the comments within the
source.
- 4. Once finished, compile the code
and check to see if it operates as
directed.
Debug the code until
it works properly.
- 5.
Verify your results from this phase.
Tips
1. Many of the functions that need to be written have already been
implemented in previous programs. Check the previous programs for possible
solutions.
2. The main data in the program will be the string[ ] array and the
letters[ ] array. string[ ] should contain the string being analyzed and
letters[ ] should be used to count the number of letter occurrences.
3. Use a for loop to count the length of the string.
|