National Institute of Technology Delhi Department of Computer Science and Engineering

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

NATIONAL INSTITUTE OF TECHNOLOGY DELHI

Department of Computer Science and Engineering

CSB451: Network Security & Cryptography

Submitted By:
Name: Kartik Kumar
Roll No: 181210026
Branch: CSE
Semester: 8th Sem

Submitted To: Dr. Karan Verma


ASSIGNMENT - 01
1. XOR a string with a Zero
AIM: Write a program that contains a string (char pointer) with a value \Hello World’. The
program should XOR each character in this string with 0 and display the result.
CODE:
#include <bits/stdc++.h>

int main()

char str[] = "Hello World";

int i, len;

len = strlen(str);

for (i = 0; i < len; i++)

printf("%c", str[i] ^ 0);

OUTPUT:
2. XOR a string with a 127
AIM: Write a program that contains a string (char pointer) with a value \Hello World’. The
program should XOR each character in this string with 127 and display the result.
Code:
#include <bits/stdc++.h>

int main()

char str[] = "Hello World";

int i, len;

len = strlen(str);

for (i = 0; i < len; i++)

printf("%c", str[i] ^ 127);

Output:

Result:
A bitwise XOR with 127 will invert the 7 low bits of every character resulting in other characters
which may be printable characters or not. That means when we print the characters we will see
"garbage".

You might also like