Professional Documents
Culture Documents
Internal External
EXPERIMENT-1
AIM: Write the code to implement Block Cipher and Play Fair Cipher with an example
output.
PROGRAM:
1. //Block cipher
#include <iostream>
#include <string>
return ciphertext;
}
int main() {
std::string plaintext;
int shift;
return 0;
}
OUTPUT:
2. //Play fair cipher
#include <iostream>
#include <vector>
#include <algorithm>
auto it = keyAndAlphabet.begin();
table[i][j] = *it++;
}
}
return table;
}
if (row1 == row2) {
ciphertext += table[row1][(col1 + 1) % 5];
ciphertext += table[row2][(col2 + 1) % 5];
} else if (col1 == col2) {
ciphertext += table[(row1 + 1) % 5][col1];
ciphertext += table[(row2 + 1) % 5][col2];
} else {
ciphertext += table[row1][col2];
ciphertext += table[row2][col1];
}
}
return ciphertext;
}
int main() {
std::string key, plaintext;
return 0;
}
OUTPUT:
EXPERIMENT-2
AIM: Implement Simplified DES (S-DES) as a symmetric-key block cipher. The S-DES
encryption algorithm takes an 8-bit block of plaintext and a 10-bit key as an input and
produces an 8-bit block of cipher text as its output.
PROGRAM:
def permute(input_block, permutation):
def generate_keys(key):
left_half = p10_key[:5]
right_half = p10_key[5:]
left_half = xor_result[:4]
right_half = xor_result[4:]
s_box_output = s_box(left_half, S0) + s_box(right_half, S1)
def initial_permutation(plaintext):
def inverse_permutation(ciphertext):
initial_permuted_text = initial_permutation(plaintext)
left_half = initial_permuted_text[:4]
right_half = initial_permuted_text[4:]
new_left_half1 = right_half
return final_ciphertext
# Example usage:
S0 = [
[1, 0, 3, 2],
[3, 2, 1, 0],
[0, 2, 1, 3],
[3, 1, 3, 2]
S1 = [
[0, 1, 2, 3],
[2, 0, 1, 3],
[3, 0, 1, 0],
[2, 1, 0, 3]
print("Ciphertext:", ciphertext)
OUTPUT: