<%@LANGUAGE="VBSCRIPT" %> <% Response.CacheControl = "no-cache" %>
Lab 8

Cryptography, Encryption, Arrays, and Caching

Instructions

This lab will give you experience using Triple-DES encryption. You will encrypt a password, store it into the database, retrieve the encrypted password, decrypt it, and display it on the screen. All layout should appear in the aspx file. All C# code should appear in the aspx.cs CodeBehind file.

This lab will also give you experience with arrays, navigating array indexes, casting characters to ASCII values, and output caching, a new concept that you must research for this lab.

Materials to turn in:

  • Lab08 Project Folder
    • default.aspx
    • default.aspx.cs
    • other associated project files

Procedures

  1. Open SQL Server Query Analyzer and run this script
    • ERD view ---- design view
    • Open Query Analyzer
    • Load this SQL script
    • Click the 'Execute Query' button
    • You are done with this script
       
  2. Use this encryption code.
     
  3. default.aspx & default.aspx.cs
    • Create Insert Textboxes for a new userID, password, name
      • Clicking the insert button will add that userID, password, name to your DB
      • Encrypt the password prior to insertion
      • Reselect the data and bind it back to the DataGrid
    • Create a selection area where you enter any userID / password
      • Clicking the get password button will form a SQL query using the submitted username & password
        • Encrypt the typed password prior to executing the SELECT statement
      • Store the encrypted value of the password into one variable
      • Decrypt the password and store it into another variable
      • Display the two variables on the screen to visually display the difference between the original text and the cipher text.
         
  4. Caesar Cipher
    • One of the first types of encryption was made by Julius Caesar. In approximately 44 BC, Julius Caesar used a simple alphabetical (letter) substitution, that offset each letter by three. For example he would take the word "help" and would move each letter ahead in the alphabet 3 letters to get "khos". He used this encryption during the Gallic wars to communicate with generals. This worked for awhile, until more people learned to read and studied his secret cipher.

      The problem with Caesar's encryption is that it can easily be broken. One can look for the letters that most frequently appear in english (for example the vowels) and look for the letters that most frequently appear in the encrypted message. These letters are probably the vowels of the real message. Once this is done, a pattern can usually be spotted as to which letters in the encrypted message are being used to replace the real letters. All encrypters that use letters to replace other letters have this problem.
       
    • Add an area to your aspx titled Caesar Cipher. In that area, include in a single horizontal line: a textbox to type text into followed by a button labeled 'encode' followed by a disabled textbox that will contain the cipher followed by a button labeled 'decode' followed by a final textbox that will contain the decoded text.
    • In the Code Behind, create a character array containing the 26 letters of the alphabet.
    • Clicking the encode button
      • Stores the text from the textbox into a character array
      • Character by Character, encode the message.
        • Convert a character to its ASCII value by simply casting it to an integer
        • Capital A is 65 in ASCII, Lower case a is 97... there is a way to use this ASCII value to determine the index of the same letter in your alphabet array.
        • You can use ToLower and ToUpper along with the initial ASCII value to determine whether the cipher character should be upper or lower.
        • Leave any non-alphabet characters in place in the cipher, simply skip them in the encoding, but include them in the cipher.
        • Shift the actual character in the message by 3 to create the cipher
      • Store the value into the cipher textbox
    • Clicking the decode button performs the reverse operation, pulling the cipher text from the cipher textbox, decoding it, and storing the result (which should match the original text) into the final textbox.
       
  5. You are creating an ASP.NET Web application for your company's main Web site to replace an outdated ASP site. The default page in the old site, default.asp, was by far the most common entry point to your site. You expect the main page of your new site, default.aspx, to be the most common entry point again and you plan to use output caching to improve response times.

    Default.aspx pulls some data from a SQL Server database to be displayed. Although some content is dynamically generated, every user receives the same content regardless of any parameters included in the message body or query string. Your office manager updates the data in the database using a Windows application. The data is usually updated once or twice a day, but sometimes more frequently. You plan to cache the page for ten minutes at a time.

    Research and correctly implement the directive that you should use in your .aspx file to configure output caching for the given scenario listed here. Place that directive in default.aspx
     

Grading

Encryption -5 pts max
Caching -5 pts max
Caesar Cipher -10 pts max
Comments -5 pts max
Total 25 pts possible