0% found this document useful (0 votes)
20 views8 pages

Encryption Report

The document describes a proposed improvement to the Vigenere cipher encryption algorithm. It introduces dynamic key expansion to generate a longer encryption key based on the plaintext length. This strengthens the encryption by overcoming shortcomings of traditional Vigenere cipher related to short keys. Pseudocode and flowcharts illustrate the new algorithm which includes dynamic key expansion, Vigenere encryption, and Vigenere decryption steps. C++ code implements the algorithm and primary purpose is to encrypt a plaintext file, write to cipher file, decrypt the cipher file and write to decoded file. Key length and computational overhead are identified as design constraints.

Uploaded by

Tala Samer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views8 pages

Encryption Report

The document describes a proposed improvement to the Vigenere cipher encryption algorithm. It introduces dynamic key expansion to generate a longer encryption key based on the plaintext length. This strengthens the encryption by overcoming shortcomings of traditional Vigenere cipher related to short keys. Pseudocode and flowcharts illustrate the new algorithm which includes dynamic key expansion, Vigenere encryption, and Vigenere decryption steps. C++ code implements the algorithm and primary purpose is to encrypt a plaintext file, write to cipher file, decrypt the cipher file and write to decoded file. Key length and computational overhead are identified as design constraints.

Uploaded by

Tala Samer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Cryptography and Network Security

Caesar Ciphering Algorithm


Assignment

Tala Samer AlZaidi 202030040


Raghad Adel Hassan 202010306
1. Introduction:

This research aims to introduce a novel Vigenere encryption and decryption technique. A
basic polyalphabetic substitution technique is used in the Vigenere cipher to encrypt
alphabetic text. The technique is more secure than a typical Caesar cipher since it employs
a keyword to change the characters in the plaintext.

2. Problem Description and Limitations

2.1 Key Length Vulnerability


The Vigenere cipher's security is mostly reliant on the keyword's length. Short keywords
make the ciphertext more vulnerable to frequency analysis, which facilitates enemy
communication decryption.
2.2 Handling of Non-Alphabetical Characters
Non-alphabetical characters are not supported by the conventional Vigenere cipher, which
could expose plaintext patterns and weaken the encryption.
2.3 Proposed Solution Overview
An algorithm for dynamic key expansion is given in order to overcome these drawbacks. A
stronger encryption is ensured by this algorithm, which creates a longer key dependent on
the length of the plaintext. The Vigenere cipher's overall security is improved, and
weaknesses related to short keywords are lessened thanks to the dynamic key expansion.

3. Description of Your Solution (New Algorithm) using


Equation, Flow Chart, and Pseudocode

3.1 Algorithm Overview:


The proposed algorithm includes the following steps:
1. Dynamic Key Expansion: Generate a key that is as long as the plaintext by repeatedly
appending the original keyword.
2. Vigenere Encryption: Encrypt the plaintext using the generated dynamic key.
3. Vigenere Decryption: Decrypt the ciphertext using the same dynamic key.

3.2 Pseudocode:

function dynamicKeyExpansion(plaintext, keyword):


key = generateDynamicKey(plaintext, keyword)
ciphertext = vigenereEncrypt(plaintext, key)
return ciphertext

function generateDynamicKey(plaintext, keyword):


key = keyword
while key.length < plaintext.length:
key += keyword
return key.substr(0, plaintext.length)

function vigenereEncrypt(plaintext, key):


// Existing Vigenere encryption logic
// ...

function vigenereDecrypt(ciphertext, key):


// Existing Vigenere decryption logic
// ...
3.3 Flow Chart (High-Level)

Start of Program

Read Keyword & Text

Generate Dynamic Key

Vigenere Encryption

Write
Ciphered Text

Vigenere Decryption

Write
Deciphered
4. Your Code with Comments and Explanation
#include <iostream>
End
#include <fstream>
#include <string>
using namespace std;

// Function to perform Vigenere encryption with dynamic key expansion


string vigenereEncryptDynamic(string plaintext, string keyword) {
// Generate a key with dynamic key expansion
string key = generateDynamicKey(plaintext, keyword);

// Initialize variables
string ciphertext = "";
int keyLength = key.length();
int textLength = plaintext.length();

// Encryption loop
for (int i = 0; i < textLength; ++i) {
char currentChar = plaintext[i];

// Check if the character is an alphabet letter


if (isalpha(currentChar)) {
char base = islower(currentChar) ? 'a' : 'A';
char shiftBase = islower(key[i % keyLength]) ? 'a' : 'A';

// Perform encryption
char encryptedChar = static_cast<char>((currentChar - base + (key[i % keyLength] -
shiftBase)) % 26 + base);
ciphertext += encryptedChar;
} else {
ciphertext += currentChar; // Keep non-alphabetical characters unchanged
}
}

return ciphertext;
}

// Function to perform Vigenere decryption with dynamic key expansion


string vigenereDecryptDynamic(string ciphertext, string keyword) {
// Generate a key with dynamic key expansion
string key = generateDynamicKey(ciphertext, keyword);

// Initialize variables
string plaintext = "";
int keyLength = key.length();
int textLength = ciphertext.length();

// Decryption loop
for (int i = 0; i < textLength; ++i) {
char currentChar = ciphertext[i];

// Check if the character is an alphabet letter


if (isalpha(currentChar)) {
char base = islower(currentChar) ? 'a' : 'A';
char shiftBase = islower(key[i % keyLength]) ? 'a' : 'A';

// Perform decryption
char decryptedChar = static_cast<char>((currentChar - base - (key[i % keyLength] -
shiftBase) + 26) % 26 + base);
plaintext += decryptedChar;
} else {
plaintext += currentChar; // Keep non-alphabetical characters unchanged
}
}

return plaintext;
}

// Function to generate a key with dynamic key expansion


string generateDynamicKey(string text, string keyword) {
string key = keyword;
while (key.length() < text.length()) {
key += keyword;
}
return key.substr(0, text.length());
}

int main() {
// Read plaintext from file
ifstream inFile("plaintext.txt");

// Create files for ciphered and deciphered texts


ofstream cipherFile("cipheredtext.txt");
ofstream decipherFile("decipheredtext.txt");

// Set the keyword


string keyword = "raghad";

// Check if files are opened successfully


if (inFile.is_open() && cipherFile.is_open()) {
string plaintext;

// Read each line from the file and perform encryption


while (getline(inFile, plaintext)) {
string ciphertext = vigenereEncryptDynamic(plaintext, keyword);
cipherFile << ciphertext << endl;
}

// Close files
inFile.close();
cipherFile.close();
cout << "Ciphering successful!" << endl;
} else {
cout << "Unable to open files for ciphering!" << endl;
}

// Read ciphered text from file


ifstream cipherInFile("cipheredtext.txt");

// Check if files are opened successfully


if (cipherInFile.is_open() && decipherFile.is_open()) {
string ciphertext;

// Read each line from the file and perform decryption


while (getline(cipherInFile, ciphertext)) {
string decryptedtext = vigenereDecryptDynamic(ciphertext, keyword);
decipherFile << decryptedtext << endl;
}

// Close files
cipherInFile.close();
decipherFile.close();
cout << "Deciphering successful!" << endl;
} else {
cout << "Unable to open files for deciphering!" << endl;
}

return 0;
-The genereEncryptDynamic function uses dynamic key expansion to carry out Vigenere
encryption. It uses the generateDynamicKey function to create a dynamic key, encrypts the
plaintext, and receives the keyword as inputs.
-The Vigenere decryption with dynamic key expansion is carried out by the
vigenereDecryptDynamic function. It decrypts the ciphertext after generating a dynamic
key using the generateDynamicKey function with the ciphertext and keyword as inputs.
-The function GenerateDynamicKey creates a key with dynamic key expansion. The original
keyword is repeated until the text is the desired length, at which point the key is truncated
to fit the text.
-primary purpose: The primary function reads text from a file in plaintext, encrypts it using
Vigenere, writes the encrypted text to a file, retrieves the encrypted text from the file,
decrypts it using Vigenere, and writes the decoded content to a different file.
}
5. Your Design Constraints
5.1 Key Length
The suggested algorithm's security depends on choosing a sufficiently long, random term.
In order to increase the encryption strength, users are advised to select a strong keyword.

5.2 Computational Overhead


The extra key generation step in the dynamic key expansion could result in a little
computational overhead. For increased security, this is regarded as a fair trade-off,
nevertheless.

6. References
D. Singh, "Cryptography and Network Security," Tata McGraw-Hill Education, 2011.

You might also like