Is Lab Manual
Is Lab Manual
INDEX
Sr. PAGE
AIM DATE REMARKS SIGN
No NO.
1 Write a program and perform Caesar cipher
algorithm in C.
2 Write a program and perform Mono alphabetic
Cipher algorithm in C.
int main() {
char text[100];
int shift;
caesarEncrypt(text, shift);
printf("Encrypted text: %s\n", text);
caesarDecrypt(text, shift);
printf("Decrypted text: %s\n", text);
return 0;
}
Output:
#define ALPHABET_SIZE 26
int main() {
char key[ALPHABET_SIZE + 1];
char plaintext[100], ciphertext[100], decrypted[100];
char subAlphabet[ALPHABET_SIZE];
// Input plaintext
printf("Enter plaintext: ");
fgets(plaintext, sizeof(plaintext), stdin);
plaintext[strcspn(plaintext, "\n")] = '\0'; // Remove newline character
return 0;
}
Output:
Enter a substitution key (26 unique letters): QWERTYUIOPASDFGHJKLZXCVBNM
Enter plaintext: HELLO
Ciphertext: HJLLT
Decrypted Text: HELLO
Practical-3
AIM: Write a program and perform Poly Alphabetic Cipher algorithm in C.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char plaintext[100], key[50], ciphertext[100], decrypted[100];
return 0;
}
Output:
Enter plaintext: Attack at dawn!
#define SIZE 5
// Encrypt digraphs
for (i = 0; i < k; i += 2) {
char a = plaintext[i];
char b = plaintext[i + 1];
int row1, col1, row2, col2;
int main() {
char key[100], plaintext[100], ciphertext[100];
char keyMatrix[SIZE][SIZE];
// Input key and plaintext
printf("Enter key: ");
fgets(key, sizeof(key), stdin);
key[strcspn(key, "\n")] = '\0'; // Remove newline character
return 0;
}
Output:
Enter key: Playfair Example
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
printf("\n");
a = a % m;
if ((a * x) % m == 1) {
return x;
adj[0][0] = matrix[1][1];
adj[0][1] = -matrix[0][1];
adj[1][0] = -matrix[1][0];
adj[1][1] = matrix[0][0];
int k = 0;
if (isalpha(plaintext[i])) {
if (k % SIZE != 0) {
plaintext[k] = '\0';
// Encrypt the plaintext
if (detInv == -1) {
return;
int adj[SIZE][SIZE];
adjugate(key, adj);
if (adj[i][j] < 0) {
}
}
int main() {
int key[SIZE][SIZE];
// Input key
scanf("%d", &key[i][j]);
// Input plaintext
return 0;
Output:
Ciphertext: XNIVR
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int k = 0;
ciphertext[k++] = rail[i][j];
}
}
int k = 0;
direction = 1;
k = 0;
int main() {
int rails;
scanf("%d", &rails);
return 0;
Output:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
} else {
} else {
int main() {
srand(time(0));
// Input plaintext
generateKey(key, strlen(plaintext));
return 0;
Output:
Ciphertext: HZPPZ
AIM: Write a program and perform Data Encryption Standard (DES) algorithm in C.
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#define DES_KEY_SIZE 8
#define DES_BLOCK_SIZE 8
int initialPermutation[64] = {
};
int finalPermutation[64] = {
};
int sBoxes[8][4][16] = {
},
},
},
},
{
{12, 1, 10, 15, 9, 2, 8, 7, 5, 6, 0, 4, 3, 14, 13, 11},
},
},
},
};
// Simplified: the initial permutation and final permutation are omitted for brevity
int main() {
uint8_t key[DES_KEY_SIZE] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
uint8_t ciphertext[DES_BLOCK_SIZE];
DES_encrypt(plaintext, key);
printf("Ciphertext: ");
printf("\n");
DES_decrypt(ciphertext, key);
Output:
Plaintext: ABCDEFGH
Ciphertext: 8B 0D 74 94 54 A3 2D E1
AIM: Write a program and perform Advance Encryption Standard (AES) algorithm in C.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
};
// Inverse S-box
};
// Round constant
};
// Function prototypes
// S-box initialization (you can find the full S-box values online)
// Rcon initialization (you can find the full Rcon values online)
// AddRoundKey function
state[i] ^= roundKey[i];
// SubBytes function
state[i] = sbox[state[i]];
// InvSubBytes function
state[i] = rsbox[state[i]];
// ShiftRows function
// InvShiftRows function
// MixColumns function
// InvMixColumns function
AddRoundKey(state, roundKeys);
SubBytes(state);
ShiftRows(state);
MixColumns(state);
SubBytes(state);
ShiftRows(state);
InvShiftRows(state);
InvSubBytes(state);
InvMixColumns(state);
InvShiftRows(state);
InvSubBytes(state);
AddRoundKey(state, roundKeys);
}
int main() {
uint8_t key[AES_BLOCK_SIZE] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
initialize_sbox();
initialize_Rcon();
KeyExpansion(key, roundKeys);
printf("Original State:\n");
printf("\n");
AES_Encrypt(state, roundKeys);
printf("Encrypted State:\n");
printf("\n");
// Decrypt the state
AES_Decrypt(state, roundKeys);
printf("Decrypted State:\n");
printf("\n");
return 0;
Output:
Original State:
32 88 31 e0 43 5a 31 37 f6 30 98 07 a8 8d 9c 26
Encrypted State:
39 25 dc 19 8c 3b 8a 1b 29 45 3e 4c 76 a2 9c 29
Decrypted State:
32 88 31 e0 43 5a 31 37 f6 30 98 07 a8 8d 9c 26
Practical – 10
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
int main() {
int e, d, n;
generateRSAKeys(&e, &d, &n);
Output:
#include <stdio.h>
#include <stdint.h>
#include <string.h>
typedef struct {
uint32_t state[8];
uint64_t bit_count;
uint8_t buffer[64];
} SHA256_CTX;
SHA256_CTX ctx;
sha256_init(&ctx);
sha256_update(&ctx, (const uint8_t *)message, strlen(message));
sha256_final(&ctx, hash);
return 0;
}
Output:
void compute_hmac(const char *key, const char *data, unsigned char *result, unsigned int
*result_len) {
HMAC_CTX *ctx = HMAC_CTX_new();
// Initialize the HMAC context with the key and the SHA256 hash function
HMAC_Init_ex(ctx, key, strlen(key), EVP_sha256(), NULL);
HMAC_Update(ctx, (unsigned char *)data, strlen(data));
HMAC_Final(ctx, result, result_len);
HMAC_CTX_free(ctx);
}
int main() {
const char *key = "secret_key";
const char *data = "Hello, world!";
unsigned char result[EVP_MAX_MD_SIZE];
unsigned int result_len;
return 0;
}
Output: