Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Assignment 2: a file encrypt or

Contents

  Aims

  Introduction

  Getting Started

  Reference Implementation

  Your Tasks

  Subset 0: File and directory commands

  Subset 1: XOR encryption

  Subset 2: Directory traversal

  Subset 3: ECB encryption

  Subset 4: Cipher block chaining encryption

  Testing

  Assumptions and Clarifications

  Assessment

  Testing

  Submission

  Due Date

  Assessment Scheme

  Intermediate Versions of Work

  Assignment Conditions

  Change Log

Aims

  to improve your understanding of filesystem objects

  to give you experience writing C code to manipulate binary files

  to further experience practical uses of bitwise operations

  to give you experience writing a relevant low-level data manipulation program in C

Introduction

Your task in this assignment is to write tide, a terribly insecure single-file encryption/decryption tool. Throughout this assignment, you will explore some basic filesystem operations, as well as implement several rudimentary encryption algorithms.

Encryption is the process of converting information into an obscured format, which can (in theory), only be converted back into useful

information by an authorized party who knows the encryption process and key. Encryption is an incredibly useful tool, and is the reason why the internet can function in the way it does, with sensitive information freely transmitted across it.

File encryption is particularly useful to safeguard data in the case that it is stolen. Encrypting your files could prevent someone from being able to access your photos in the event that your laptop gets stolen.

In this assignment, you will implement three different algorithms for file encryption: XOR (eXclusive OR), ECB (Electronic Code Book) and CBC    (Cipher Block Chaining). Each of these algorithms function slightly differently, but all work towards the same purpose of obscuring information, that can only be correctly interpreted by an authorised party.

XOR encryption works by employing the bitwise XOR operation on every bit of some given data. A key, which when broken up into its   constituent bits, is expanded to match the length of the data being encrypted. The XOR operation is then employed between these two

bitstreams to yield the encrypted data. This encrypted data can be decrypted only by re-running the same XOR operation with the same key. In tide, standalone XOR encryption will only employ the the single-byte key   0xA9 .

ECB encryption works by bit-shifting data by the amount specified by some key (a password). Each character in a 'block' of the input data is

shifted by the value of the character in the corresponding position within the password. The encrypted data can be decrypted only by shifting it back by the value of the corresponding position within the password. In tide, passwords will be a fixed length of 16 characters.

CBC encryption is different from the above two algorithms as each block of the encrypted data contributes to the encryption of the next block.

We will combine both XOR encryption and ECB encryption to develop an encryption algorithm where it is significantly harder for an unauthorised party to read our encrypted data by guessing our password.

However, before all of this, tide needs to be able to function as a basic standalone program. As such, we will implement several filesystem

manipulation operations. You will also implement two different methods of searching for files, which will make the user's life easier in finding what they might need to encrypt.

Getting Started

Create a new directory for this assignment called   tide , change to this directory, and fetch the provided code by running these commands:

$ mkdir -m 700 tide

$ cd tide

$ 1521 fetch tide

If you're not working at CSE, you can download the provided files as a zip file or a tar file.

This will get you  tide.c , which contains code to start the assignment. As provided, it will compile and run, but lacks any real functionality:

$ make

dcc -Wall -Werror main.c tide.c -o tide

$ ./tide

Welcome to tide!

To see what commands are available, type help.

tide> help

 

help (h)

Prints this help message

pwd (p)

Prints the current directory

chdir directory (cd)

Changes the current directory

list (ls)

Lists the contents of the current directory

test-encryptable filename (t)

Tests if a file can be encrypted

xor-contents filename (x)

Encrypts a file with simple XOR

encrypt-ecb filename (ee)

Encrypts a file with ECB

decrypt-ecb filename (de)

Decrypts a file with ECB

search-name search-term (sn)

Searches for a file by filename

search-content search-size (sc)

Searches for a file by its content for the provided bytes

search-from-file source-file (sf) Searches for a file by its content for the provided bytes, supplied from a file

encrypt-cbc filename (ec)         Encrypts a file with CBC

decrypt-cbc filename (dc)         Decrypts a file with CBC

quit (q)                          Quits the program

tide> q

Thanks for using tide. Have a nice day!

However,  tide.c also contains some provided functions to make your task easier. For example, the   sort_strings function will sort an array of strings into alphabetical order in-place. You should read through the provided code in this file before you begin work on this assignment.

You may also find the provided constants, data types and function signatures in   tide.h to be useful.

Reference implementation

We've written a solution to the assignment, compiled it and made it available to you as a reference implementation

A reference implementation is a common, efficient, and effective method to provide or define an operational specification; and it's something you will likely work with after you leave UNSW.

You can run the reference implementation as:   1521 tide , and see the correct output and behaviour for any input: