Professional Documents
Culture Documents
Crypto Da2
Crypto Da2
Crypto Da2
Reg No:21BCT0093
Date:26/02/2024
Cryptography and network security Lab DA 2
1. For the following plaintext and key given below, apply the hill cipher technique for
encryption and decryption. Compare the simulated result with theoretical calculations.
Plaint text: Attack is Tonight
CODE:
#include <stdio.h>
#include <vector>
a = a % m;
if ((a * x) % m == 1)
return x;
return -1;
}
// Function to calculate the inverse of a 2x2 matrix
inverse[0][0] = matrix[1][1];
inverse[0][1] = -matrix[0][1];
inverse[1][0] = -matrix[1][0];
inverse[1][1] = matrix[0][0];
inverse[i][j] *= modInv;
return inverse;
return result;
int n = keyMatrix.size();
vector<int> numericalValues;
if (isalpha(c)) {
numericalValues.push_back(tolower(c) - 'a');
vector<vector<int>> ciphertextMatrix;
vector<int> row;
row.push_back(numericalValues[i + j]);
ciphertextMatrix.push_back(row);
}
string plaintext;
return plaintext;
int main() {
vector<vector<int>> keyMatrix = {
{3, 10},
{20, 9}
};
return 0;
OUTPUT:
2.
Encode and decode the given plaintext “Attack is Tonight” using vignere cipher. Assume that,
the key is “cipher”. Compare the simulated result with theoretical calculations.
Code:
#include <stdio.h
>
#include <string>
char encryptedChar;
if (isupper(plainChar)) {
} else if (islower(plainChar)) {
} else {
encryptedChar = plainChar;
ciphertext += encryptedChar;
return ciphertext;
}
char plainChar;
if (isupper(encryptedChar)) {
} else if (islower(encryptedChar)) {
} else {
plainChar = encryptedChar;
plaintext += plainChar;
return plaintext;
int main() {
// Encode plaintext
return 0;
Output: