Skip to content

This Python program implements the RC6 encryption algorithm and the Cipher Feedback (CFB) mode of operation. The program allows users to encrypt and decrypt messages securely using a randomly generated key and initialization vector (IV). Dependencies

Notifications You must be signed in to change notification settings

husnain-ce/RC6-Encryption-Algorithm-with-CFB-Mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Here's a description of the flow and components in the program:

Key Generation: A Fernet key is generated using Fernet.generate_key(). The first 16 bytes of the Fernet key are used for RC6 encryption.

Initialization Vector (IV) Generation: An IV of 16 bytes is generated using os.urandom(16).

RC6 Initialization: An instance of the RC6_CFB class is created using the key and IV. The RC6_CFB class initializes an instance of the RC6 class using the key. The RC6 class generates round keys using the generate_round_keys() method.

Encryption: The plaintext is encrypted using the encrypt() method of the RC6_CFB class. The encrypt() method encrypts each block of the plaintext using the encrypt_block() method of the RC6 class in CFB (Cipher Feedback) mode.

Decryption: The ciphertext is decrypted using the decrypt() method of the RC6_CFB class. The decrypt() method decrypts each block of the ciphertext using the decrypt_block() method of the RC6 class in CFB mode.

RC6 Encryption Algorithm with CFB Mode

This Python program implements the RC6 encryption algorithm and the Cipher Feedback (CFB) mode of operation. The program allows users to encrypt and decrypt messages securely using a randomly generated key and initialization vector (IV). Dependencies

To run this program, you need to have the following dependencies installed:

  • Python 3.x
  • Cryptography library

You can install the Cryptography library using pip:

pip install cryptography

Program Structure

The program consists of the following classes and functions:

int_to_bytes: A utility function that converts an integer to its byte representation. bytes_to_int: A utility function that converts a byte representation to its integer form. rol: A utility function that performs left rotation on an integer. ror: A utility function that performs right rotation on an integer. RC6: A class that implements the RC6 encryption algorithm. init: Initializes the RC6 object with a given key. generate_round_keys: Generates round keys required for the encryption and decryption process. encrypt_block: Encrypts a 16-byte block of plaintext using RC6. decrypt_block: Decrypts a 16-byte block of ciphertext using RC6. RC6_CFB: A class that implements the RC6 algorithm with the CFB mode of operation. init: Initializes the RC6_CFB object with a key and an initialization vector (IV). encrypt: Encrypts a given plaintext using RC6 and CFB mode. decrypt: Decrypts a given ciphertext using RC6 and CFB mode. main: The main function that demonstrates the usage of RC6_CFB for encryption and decryption.

Usage

To use the program for encrypting and decrypting messages, follow these steps:

Import the required classes and functions:

python

from RC6_CFB import RC6_CFB
import os

Generate a random key and IV:

` key = os.urandom(16) iv = os.urandom(16)

Initialize an RC6_CFB object with the key and IV:

python

`rc6_cfb = RC6_CFB(key, iv)`

Encrypt a plaintext message:

plaintext = b'This is a test message.'
encrypted = rc6_cfb.encrypt(plaintext)
print('Encrypted ciphertext:', encrypted)

Decrypt the ciphertext back to the original plaintext:

decrypted = rc6_cfb.decrypt(encrypted)
print('Decrypted plaintext:', decrypted)

Example

Here's an example of how to use the program for encrypting and decrypting a message:

import os
from RC6_CFB import RC6_CFB

key = os.urandom(16)
iv = os.urandom(16)
rc6_cfb = RC6_CFB(key, iv)

plaintext = b'This is a test message.'
print('Original plaintext:', plaintext)

encrypted = rc6_cfb.encrypt(plaintext)
print('Encrypted ciphertext:', encrypted)

decrypted = rc6_cfb.decrypt(encrypted)
print('Decrypted plaintext:', decrypted)

This example demonstrates the encryption and decryption of a test message using the RC6 encryption algorithm with CFB mode.

About

This Python program implements the RC6 encryption algorithm and the Cipher Feedback (CFB) mode of operation. The program allows users to encrypt and decrypt messages securely using a randomly generated key and initialization vector (IV). Dependencies

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages