CNS Lab Record Print
CNS Lab Record Print
一䔀䔀刀䤀
一䜀 ☀ 吀䔀䌀䠀一伀䰀伀䜀夀
COMPUTERSCI
ENCEANDENGI
NEERI
NG
ADITYA COLLEGE OF ENGINEERING AND TECHNOLOGY
VISION:
To induce higher planes of learning by imparting technical education with
International standards
Applied research
Creative Ability
Value based instruction and to emerge as a premiere institute
MISSION:
VISION:
MISSION:
Write a C program that contains a string(char pointer) with a value\Hello World’. The
programs should XOR each character in this string with 0 and display the result.
#include<stdlib.h>
main()
{
char str[]="Hello World";
char str1[11];
int i,len;
len=strlen(str);
for(i=0;i<len;i++)
{
str1[i]=str[i]^0; printf("%c",str1[i]);
}
printf("\n");
}
Output:
HELLO WORLD
Write a C program that contains a string (char pointer) with a value \Hello World’. The
program should AND or and XOR each character in this string with 127 and display the
result.
#include <stdio.h>
#include<stdlib.h>
void main()
{
char str[]="Hello World";
char str1[11];
char str2[11];
int i,len;
len = strlen(str);
for(i=0;i<len;i++)
{
str1[i] = str[i]&127;
printf("%c",str1[i]);
}
printf("\n");
for(i=0;i<len;i++)
{
str2[i]=str2[i]^127;
printf("%c",str2[i]);
}
printf("\n");
}
OUTPUT:
Hello World
ÇÇÇÇÇÇÇÇU
Write a Java program to perform encryption and decryption using the following algorithms:
i. Ceaser Cipher ii. Substitution Cipher iii. Hill Cipher
Ceaser Cipher:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
Output:
Output:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import java.util.Base64;
Output:
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.Key;
import java.util.Base64;
int input;
// Read bytes from input file and write to encrypted output file
while ((input = fin.read()) != -1) {
cout.write(input);
}
Output:
input = "abc";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("MD5(\"" + input + "\") = " + bytesToHex(output));
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("MD5(\"" + input + "\") = " + bytesToHex(output));
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
public static String bytesToHex(byte[] b) {
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuffer buf = new StringBuffer();
for (int j = 0; j < b.length; j++) {
buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
buf.append(hexDigit[b[j] & 0x0f]);
}
return buf.toString();
}
}
Output: