Coder Social home page Coder Social logo

halloweeks / aes-ecb-in-c Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 22 KB

This project demonstrates AES (Advanced Encryption Standard) encryption and decryption in ECB (Electronic Codebook) mode using C language.

License: MIT License

C 100.00%

aes-ecb-in-c's Introduction

AES ECB Encryption and Decryption

This project provides a simple implementation of AES (Advanced Encryption Standard) encryption and decryption in ECB (Electronic Codebook) mode.

Features

  • AES Encryption Decryption: Supports AES-128bit, AES-192bit, and AES-256bit.
  • ECB Mode: Implements the Electronic Codebook mode, which encrypts and decrypts each block of data independently.

Usage

  1. Clone the repository to your local machine:

    git clone https://github.com/halloweeks/aes-ecb-in-c.git
  2. Compile the code using your preferred C compiler:

    gcc main.c -o main.exe
  3. Run the program:

    ./main.exe

Example AES 256

#include <stdio.h>
#include <stdint.h>
#include "aes.h"

int main() {
    // Define your 16-byte plaintext and key
    uint8_t plaintext[16] = "Hello, AES ECB!";
    uint8_t key[32] = {
        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
        0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
        0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
        0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
    };

    // Create an array for the ciphertext (16 bytes)
    uint8_t ciphertext[16];

    // Encrypt the plaintext
    AES_ecb_encrypt(plaintext, ciphertext, key, 256);

    // Print the ciphertext
    printf("Ciphertext: ");
    for (int i = 0; i < 16; i++) {
        printf("%02X ", ciphertext[i]);
    }
    printf("\n");

    // Decrypt the ciphertext
    AES_ecb_decrypt(ciphertext, plaintext, key, 256);

    // Print the decrypted plaintext
    printf("Decrypted: %s\n", plaintext);

    return 0;
}

Supported Key Sizes

  • AES-128 (128-bit key)
  • AES-192 (192-bit key)
  • AES-256 (256-bit key)

Acknowledgments

  • AES fixed block size is 16 bytes, the maximum data size for a single block of encryption or decryption is 16 bytes (128 bits).
  • To encrypt or decrypt data larger than 16 bytes, you should divide it into 16-byte blocks and process each block independently.

License

This project is licensed under the MIT License. See the LICENSE file for details.

aes-ecb-in-c's People

Contributors

halloweeks 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.