IU2241230284 Cryptography and Network Security
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-A:
#include <stdio.h>
int main() {
char *str = "Hello World";
int i = 0;
printf("Original String: %s\n", str);
printf("Character | XOR with 0 | AND with 0 | OR with 0\n");
printf("------------------------------------------------\n");
while (str[i] != '\0') {
char ch = str[i];
printf(" %c | %d | %d | %d\n", ch, ch ^ 0, ch & 0, ch | 0); i++;
}
return 0;
}
6CSE-B 1
IU2241230284 Cryptography and Network Security
OUTPUT:
CODE-B:
#include <stdio.h>
int main() {
char *str = "Hello World";
int i = 0;
printf("Original String: %s\n", str);
printf("Character | XOR with 127 | AND with 127 | OR with 127\n");
printf("----------------------------------------------------\n");
while (str[i] != '\0') {
char ch = str[i];
printf(" %c | %d | %d | %d\n", ch, ch ^ 127, ch & 127, ch | 127); i++;
}
return 0;
}
6CSE-B 2
IU2241230284 Cryptography and Network Security
OUTPUT:
CODE-C:
#include <stdio.h>
int main() {
char *str = "Hello World";
int i = 0;
printf("Original String: %s\n", str);
printf("Character | OR with 127 | Left Shift by 1 | Right Shift by 1\
n"); printf("--------------------------------------------------------\n");
while (str[i] != '\0') {
char ch = str[i];
printf(" %c | %d | %d | %d\n", ch, ch | 127, ch << 1, ch >> 1); i++;
}
return 0;
}
OUTPUT:
6CSE-B 3
IU2241230284 Cryptography and Network Security
6CSE-B 4