CNS prac YATHARTH
CNS prac YATHARTH
Practical - 1
AIM: A. Write a C program that contains a string (char pointer) with a value 'Hello
World’. The program should XOR, AND and OR each character in this string with 0
and displays the result.
B. Write a C program that contains a string (char pointer) with a value 'Hello
World’. The program should XOR, AND and OR each character in this string with
127 and displays the result.
C. Write a C program that contains a string (char pointer) with a value 'Hello
World’. The program should bitwise OR, left shift and right shift each character in
this string and displays the result.
Code:
#include <stdio.h>
#include <string.h>
int main() {
6CSE-E1 1
IU2241230105 Cryptography and Network Security
bitwise_operations(text, 0);
bitwise_operations(text, 127);
shift_operations(text);
return 0;
}
Output:
6CSE-E1 2
IU2241230105 Cryptography and Network Security
6CSE-E1 3
IU2241230105 Cryptography and Network Security
Practical - 2
AIM: To implement Caesar Cipher Encryption – Decryption.
Code:
#include <stdio.h>
#include <string.h>
int main() {
char text[100];
int shift;
6CSE-E1 4
IU2241230105 Cryptography and Network Security
scanf("%s", text);
printf("Enter shift value: ");
scanf("%d", &shift);
caesarEncrypt(text, shift);
printf("Encrypted text: %s\n", text);
caesarDecrypt(text, shift);
printf("Decrypted text: %s\n", text);
return 0;
}
6CSE-E1 5
IU2241230105 Cryptography and Network Security
Practical - 3
AIM: To implement Mono-alphabetic Cipher Encryption – Decryption.
Code:
#include <stdio.h>
#include <string.h>
#define ALPHABET_SIZE 26
6CSE-E1 6
IU2241230105 Cryptography and Network Security
}
}
int main() {
char text[100];
monoEncrypt(text);
printf("Encrypted text: %s\n", text);
monoDecrypt(text);
printf("Decrypted text: %s\n", text);
return 0;
}
Output:
6CSE-E1 7
IU2241230105 Cryptography and Network Security
Practical - 4
AIM: To implement Hill Cipher Encryption.
Code:
#include <stdio.h>
#include <string.h>
#define MATRIX_SIZE 2
6CSE-E1 8
IU2241230105 Cryptography and Network Security
int main() {
char text[100];
int key[MATRIX_SIZE][MATRIX_SIZE] = {{6, 24}, {1, 13}};
hillEncrypt(text, key);
printf("Encrypted text: %s\n", text);
return 0;
}
Output:
6CSE-E1 9
IU2241230105 Cryptography and Network Security
Practical - 5
AIM: To implement Poly-alphabetic Cipher (Vigener Cipher) Technique.
Code:
#include <stdio.h>
#include <string.h>
int main() {
6CSE-E1 10
IU2241230105 Cryptography and Network Security
vigenereEncrypt(text, key);
printf("Encrypted text: %s\n", text);
vigenereDecrypt(text, key);
printf("Decrypted text: %s\n", text);
return 0;
}
Output:
6CSE-E1 11
IU2241230105 Cryptography and Network Security
Practical - 6
AIM: To implement Play-Fair Cipher Technique.
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define SIZE 5
char keyTable[SIZE][SIZE];
6CSE-E1 12
IU2241230105 Cryptography and Network Security
if (r1 == r2) {
text[i] = keyTable[r1][(c1 + 1) % SIZE];
text[i + 1] = keyTable[r2][(c2 + 1) % SIZE];
} else if (c1 == c2) {
text[i] = keyTable[(r1 + 1) % SIZE][c1];
text[i + 1] = keyTable[(r2 + 1) % SIZE][c2];
} else {
text[i] = keyTable[r1][c2];
text[i + 1] = keyTable[r2][c1]}
6CSE-E1 13
IU2241230105 Cryptography and Network Security
}
}
int main() {
char key[26], text[100];
generateKeyTable(key);
playfairEncrypt(text);
printf("Encrypted text: %s\n", text);
return 0;
}
Output:
6CSE-E1 14
IU2241230105 Cryptography and Network Security
Practical - 7
AIM: To implement Caesar Cipher Encryption – Decryption.
Code:
#include <stdio.h>
#include <string.h>
char rail[key][len];
memset(rail, '\n', sizeof(rail));
6CSE-E1 15
IU2241230105 Cryptography and Network Security
printf("\n");
}
int main() {
char text[100];
int key;
railFenceEncrypt(text, key);
return 0;
}
Output:
6CSE-E1 16