Git Product home page Git Product logo

cryptography's Introduction

Cryptography

An implementation of basic ciphers, authentication codes and common attacks.

Implementations

1. Block Cipher(AES)

Implementing a block cipher in both CBC(Chained block cipher) and CTR(counter) mode using AES in ECB(Electronic codebook) mode. CBC MODE CBC mode

CTR MODE CTR mode

Since CTR mode is not chained it can be parallelised and it uses the pathos.multiprocessing library of python to distribute each block to a different core. Encyption and decryption of a 3.9MB file takes 6.5 seconds, I found that parallelisation did not offer significant improvement in speed as the majority of the time is spent in copying the large text rather than the encryption part.

2. Video Authentication

To authenticate a streamed video against tampering, a SHA256 hash is computed on it. To allow live playing of the video it is broken into chunks and a chained hash is calculated as shown: Video authentication

Attacks

1. Many time pad attack

Attack on a one time pad when the same stream cipher key is used more than once to encrypt text The attack leverages patterns in the ASCII representation of text to completely decrypt the target ciphertext when given 10 ciphertexts encrypted with the same OTP. In particular we consider what happens when a space character gets xored with a alphabet - It inverts the case of the character. Then by xor'ing the target ciphertext with each of the given ciphertexts we can determine the character present at each position.

2. Padding oracle attack

The dummy website contains encrypted customer data in its url and uses a chained block cipher for encryption. When the padding for the decrypted CBC ciphertext is invalid it returns a HTTP 403 error(forbidden request). However if the padding is valid but the decrypted message is invalid it returns a HTTP 404 error(URL not found).

Using only this information the padding oracle is able to completely decrypt the ciphertext in at most requests to the server The implementation used a few tricks to speedup the attack such as :

  • Use the multiprocessing library in python to speedup the attack by parallelising it across all cores of the CPU
  • Each block of the text is assigned to a different core
  • Instead of checking all ASCII characters in order it uses a frequency table to check in order of occurence frequency

On a 8 core processor the attack takes 372 seconds for 3 blocks of AES-128 ciphertext Padding oracle

3. Meet in the middle attack for discrete log

Given a large prime p of size 500 bits , a generator g, h from the group such that where

We need to find the exponent x. The brute force algorithm takes Using a meet in the middle method by maintaining a hash table we can reduce this to i.e by writing the exponent x as where

We hash values of the LHS and check the RHS for each value. After optimizations the attack completes in 1.5 seconds using gmpy2 library in python

4. RSA

Various attacks on RSA when various conditions for choosing primes are relaxed Let N be the RSA modulus where N=pq for large primes p,q

a)

We can find p,q in constant time

b)

We can find p,q in iterations

c)

We can find p,q in constant time

5. Caesar Cipher

A basic implementation of the caesar cipher for encryption

6. Frequency attack

A brute force frequency attack to show the weakness of caesar cipher.

Compares the frequency of all possible decryption with the expected frequency of the english alphabet and chooses the one with minimum L1 distance.

7. SDES implementation

An implementation of Simples DES

cryptography's People

Stargazers

Eklavya Jain avatar

Watchers

James Cloos avatar Kousik Rajesh avatar

Forkers

whendustsettles

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.