Giter Site home page Giter Site logo

aes256_encryption_algorithm's Introduction

AES (Advanced Encryption Standard) Cipher and CBC (Cipher Block Chaining)

AES is a symmetric cipher used for encryption and decryption of data. It operates on a 4x4 grid of 128 bits (16-byte blocks) and supports key lengths of 128, 192, or 256 bits.

AES Encryption Steps:

plaintext
|
|
+ (XOR)@ <-- Initialisation vector (IV)
|
|
+ block cipher <-- Key
|
|
+ cipher text


  1. Initial XOR with Key: Plaintext is combined with the initial round key.
  2. Substitute Bytes: Byte substitution using an AES lookup table.
  3. Shift Rows: Rows of the grid are shifted cyclically to the left.
  4. Mix Columns: Matrix multiplication in a Galois finite field (except in the last round).
  5. Add Round Key: Round key is XORed with the result of the previous steps.

AES Decryption Steps:

cipher text
|
|
+ (XOR)@ <-- Initialisation vector (IV)
|
|
+ block cipher <-- Key
|
|
+ plaintext

Decryption involves reversing the encryption steps, with the IV used to maintain randomness and uniqueness of ciphertexts.

Key Points:

  • AES encryption involves multiple rounds, each performing a specific transformation on the data.
  • CBC mode enhances security by XORing each plaintext block with the previous ciphertext block before encryption.
  • The IV is crucial for CBC mode to ensure unique ciphertexts.

Code Example:

#ENCRYPTOR WHICH WRITES THE ENCRYPTION AND THE VI TO A FILE
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from Crypto.Util.Padding import unpad

key = b'mysecretpassword' #16 bit key

cipher = AES.new(key,AES.MODE_CBC)

plaintext = b'this is some important data'

ciphertext = cipher.encrypt(pad(plaintext,AES.block_size))


with open('k_file','wb')as key_file:
    key_file.write(cipher.iv)
    key_file.write(ciphertext)

#DECRYPTOR WHICH TAKES FROM THAT FILE TO CONVERT BACK TO PLAIN TEXT
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
import os
import base64

from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from Crypto.Util.Padding import unpad
from Crypto import Random
from Crypto.Hash import SHA256
import base64
import sys

key = b'mysecretpassword' #16 bit key

with open('k_file', 'rb') as key_file:
    iv = key_file.read(16)
    ciphertext = key_file.read()


cipher= AES.new(key,AES.MODE_CBC, iv)

plaintext = unpad(cipher.decrypt(ciphertext), AES.block_size)

print(plaintext.decode())

aes256_encryption_algorithm's People

Contributors

hardikkum444 avatar

Stargazers

 avatar

Watchers

 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.