Skip to content

ashtonmendes/Visual-Cryptography

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

<TITLE>Homework #2 - CSCI 531, Spring 2015</TITLE>
<TD ALIGN=LEFT VALIGN=TOP>
<!-- COL 3, every page should be different -->
    <TABLE BORDER=0>
    <TR><TD COLSPAN=3 ALIGN=LEFT>

The purpose of this assignment is to get you familiar with visual cryptography. Please see Doug Stinson's visual cryptography page for an introduction. Our assignment will be slighly different from what's on Doug Stinson's page

 
Compiling
make hw2
an executable named hw2 is created.
        </TD>
    </TR>
    <TR><TD>&nbsp;</TD></TR>
    <!-- Section -->
    <TR><TD COLSPAN=3 ALIGN=LEFT BGCOLOR="#000000" WIDTH=100%>
            <FONT COLOR="#ffffff"><A
            NAME="syntax"><B>Commandline Syntax & Program
            Output</B></A></FONT>
        </TD>
    </TR>
    <!-- Top Section -->
    <TR><TD COLSPAN=3 ALIGN=LEFT>

The commandline syntax for hw2 is as follows:

    hw2 stream -p=pphrase -l=len
    hw2 encrypt -p=pphrase -out=name [pbmfile]
    hw2 merge pbmfile1 pbmfile2
    hw2 decrypt [pbmfile]

Square bracketed items are optional. Follows the UNIX convention that commandline options can come in any order. (Note: a commandline option is a commandline argument that begins with a - character in a commandline syntax specification.) If pbmfile is not specified, the program reads from stdin. pbmfile refers to a file in the Portable Bitmap (or PBM) format with P4 being the magic number. Output of the program goes to stdout and error messages go to stderr.

The meaning of the commands are:

stream   :   A simple stream cipher.
The ASCII string pphrase contains the passphrase (which must not be empty) for key generation and len is the number of bytes to output.
 
encrypt   :   Encrypts an input PBM file with the simple stream cipher. This should create 2 output files having the same filename as name but one with .1.pbm appended and the other with .2.pbm appended to the filenames. For example, if name is foo, the output file names must be foo.1.pbm and foo.2.pbm. The relationship between an input pixel, a key bit, and pixels in the output files is specified in the table above.
 
merge   :   Create an output PBM file by merging the bits of PBM files pbmfile1 and pbmfile2. A bit value of 1 is treated as a black pixel and a bit value of 0 is treated as a white pixel. When merging a bit of 1 and a bit of 0, the output must be a 1. You must use 0 as the padding bit at the end of a row in the output PBM file.
 
decrypt   :   Treats the input PBM file as the result of the merge command and perform the reverse of the encryption algorithm. The resulting image size should be 1/4 of the original input.

The output for various commands are as follows.

stream   :   The output is a binary stream of bytes of length len.
 
encrypt   :   There is no output for this command. The side effect of this command is to create two files in the P4 PBM format.
 
merge   :   The output of this command is a file in the P4 PBM format.
 
decrypt   :   The output of this command is a file in the P4 PBM format.
 

 
Key Generation for a Simple Stream Cipher
Let p be a null-terminated string containing the passphrase. Please ues the following algorithm (or equivalent) to generate key stream for our simple stream cipher. (Please make appropriate modifications to make it work according to spec.) At the end of every iteration, 8 bytes of the key stream are generated.
    #include <sys/types.h>
    #include <openssl/md5.h>  /* please read this */
char md5_buf[MD5_DIGEST_LENGTH];
int len=strlen(p)+2+MD5_DIGEST_LENGTH;
char *s=malloc(len+1);
int i=0;

MD5(p, strlen(p), md5_buf);
for (;;) {
    sprintf(&s[MD5_DIGEST_LENGTH], "%02d%s", i, p);
    memcpy(s, md5_buf, MD5_DIGEST_LENGTH);
    MD5(s, len, md5_buf);
    fwrite(md5_buf, 1, sizeof(md5_buf)>>1, stdout);
    if (++i == 100) i = 0;
}
free(s);</PRE>

The idea here is that the buffer whose MD5 checksum is getting computed has 3 parts. The first part is 16 bytes long and it is the MD5 checksum of the previous value of the buffer. The 2nd part is an ASCII string of length 2 that takes on the value from "00" through "99". The 3rd part is the passphrase. Initially, the first part is the MD5 checksum of the passphrase.

For example, if pphrase is "yesnomaybe", the 3 parts of the buffer is, initially, in hexstring representation, 69cbe89bfa6370e0ab07df9a6096d3d2, 3030, and 7965736e6f6d61796265. The MD5 checksum of this buffer is cf686d0977103817538bfefdf271be2f. Therefore, the first 8 bytes of our simple stream cipher output is cf686d0977103817.

In the 2nd interation, The 3 parts of the buffer is, hexstring representation, cf686d0977103817538bfefdf271be2f, 3031, and 7965736e6f6d61796265. The MD5 checksum of this buffer is aa632cf32cd1740c1544816ac51fa9d0. Therefore, the first 8 bytes of our simple stream cipher output is aa632cf32cd1740c.

Information about the MD5 algorithm can be found at http://www.openssl.org/docs/crypto/md5.html.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors