Code Monkey home page Code Monkey logo

des's Introduction

DES

Python Implementation

DES core program has been written in a C-like fashion with a lot of bit-level operators (as shifts <<, >> and so on). For now, one can only perform ECB encryption/decryption. The git includes a bash script that allows the user to encrypt/decrypt the content of a given folder recursively (Yesh, I know, it would have been more clever to compress the directory beforehand but goal of the project was also to learn some bash).

To run the bash script, type the following

./src/encrypt_folder.sh "encrypt" "./test/" "./test_des/

where "encrypt" can be replaced by "decrypt" depending on the purpose. First argument is the input (i.e. the folder to be encrypted) and second is the output folder path (that should not already exist).

Encryption is performed with the 0xDEADBEEF default key and can be changed by editing encrypt_folder.sh. Moreover, one also has to define the python scripts path (in the DES_path variables).

Encryption/Decryption is not that fast (85 seconds to encrypt a 1.5 MB file on a 3.6 GHz machine).

If you meet any bug, don't hesitate to contact me ;-)

PS : Please note the DES constants part has been copied/pasted from Robin David's git (https://github.com/RobinDavid/pydes).

C Implementation

The C implementation was written in order to compare performances (compiled language versus interpreted language). The implementation was thought for 8-bit architecture, i.e. all operations are performed with byte granularity (no use of 16-bit or 32-bit integers or even bigger). Thus, this code could be utilized on small Arduino (as the Nano for instance). This is no surprise to observe a "gap". We observed (at least) a 10 speedup factor in favor of C. See below:

benchmark

A DES is called #iterations times (from 10,000 to 100,000 with a 10,000 steps). Benchmark consists in computing DES(DES(...(DES(0x0))) where DES is called #iterations times. Of course, we obtain a linear behaviour depending on #iterations. Overall, a single DES computation time is reported in the following table.

Python (Pentium @ 3.6 GHz) C (Pentium @ 3.6 GHz) Arduino Nano (atmega328p @ 16 MHz)
DES Execution Time (ms) ≈ 0.268 ≈ 0.009 ≈ 63,8

Benchmarks were run on a 3.6 GHz machine/Arduino Nano @ 16 MHz. I was quite amazed by the Nano performance !

I don't really know how to "interpret" the results. This "gap" was actually expected. However, it is trully substantial. Maybe, I did not code in a "pythonic" way, plus I'm quite sure Python does not "like" bit-level operations that much.

PS : Valgrind approved :-)

## What about saving the round keys once for all (in case DES is called several times with the same key) ?

Yes, it needs to be done (for both implementations).

Makefile

Run make in the main folder to compile the C code (gcc). Type make benchmark to run the benchmark. Note the bench requires gnuplot for graph generation. If not installed, the generation will fail but results could still be read from benchmark.txt.

des's People

Contributors

jeremymet avatar jmetairie avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.