Encryption Program

Caesar Cipher

In cryptography, a Caesar cipher, also known as the shift cipher is one of the simplest and most widely known encryption technique. The action of a Caesar cipher is to replace each plaintext letter with one a fixed number of places down the alphabet. The method is named after Julius Caesar, who used it to communicate with his generals.

This definition is found at http://en.wikipedia.org/wiki/Caesar_cipher#Example

The ASCII code scheme is easily utilized to make a simple Caesar cipher. See link. Since C++ treats characters as integers, we can add or subtract integers to create the encoded letter.


Simple encryption / decryption

Write a program that will encrypt and decrypt a 5 letter word. The user needs to enter a 5 letter word at the keyboard. The program encrypts the word, print it out, then reverse the word and print the original word again.

  • Start a new project, call it lab2ex2.
  • Get a copy of the encryption.cpp file by click on it: Copy it.
  • Back to your Visual C++ project, from the menu, choose Project --> Add New Item , make sure it is a C++ file under the template window, give a filename, call it encryption.cpp, then click on add.
  • Now, paste the program.
  • Compile and run this C++ program.

    Watch how each value changes by using Visual C++ debugger

    You can use the debugging tool to see how each value changes in the encryption program.

    1. Setup a breakpoint. A breakpoint is any point in the executable code where the execution stops. A breakpoint pauses the execution of a program so that the programmer can take a look at what is going on inside the program when it runs. To do this, click on the shaded bar to the left of the cout statement. (See the following figure:).

    2. Now we need to RUN the code with debugging.

      Select Debug --> Start Debugging from the main menu. The program will start to execute, then stop at the breakpoint.

    3. At this point, the output window is asking you for a five letter input, please enter apple, then press enter.

      Notice that the output window (at the bottom) splits into two windows with tabs. The VC++ work windows have changed, now showing the source code window across the top. A yellow arrow, which indicates the current line of code being executed, has appeared on top of the red "breakpoint" dot.

      The bottom appears two windows.

      The Locals window displays the current local variables and parameters and allows you to change the values of these variables interactively during code execution.

      The Autos Window displays variables used in the current statement.

      You can use either the autos windows or the locals window to see how each value changes. Right now, the execution of your program halts after the first cout statement is executed, because we set a breakpoint there. This is indicated by a yellow arrow inside the red dot. Let's step into the loop and see what happens.

    4. On the Tool bar are three important icons to use with the debugger.

      One shows a blue arrow jumping over some lines of code (Step Over F10) . Another shows the arrow pointing into the braces (Step Into F11) . These are the buttons for single stepping through a program. There is also, the Step Out button, which allows you to skip large blocks of code in debugging. Let's use the Step Over Button first.

      Press the Step Over button, the yellow arrow will move to the next line. Keep pressing the Step Over button to see how each value changes, the color change of value means the values are updated. Carefully watch how each value changes.

    5. At any point, you can stop debugging. To stop debugging, choose Debug--> Stop Debugging from the menu at the top.