Assignment 3
Assignment 3
#include<stdio.h>
int main()
{
int i=0,count=0;
char databits[80];
#include<stdlib.h>
int main()
{
system("C:\\Windows\\System32\\ipconfig");
return 0;
}
pg. 3
6. ARP Simulation
This program will find Physical Address for the given IP address.
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *f1, *fopen();
int ch;
char str1[80], *token;
const char str[80] = "", s[2] = " ";
f1 = fopen("arp.txt","r");
if ( f1 == NULL ) /* check does file exist*/
{
printf("Cannot open file for reading \n" );
exit(1);
}
while(fgets(str1,80,f1)!=NULL){
token = strtok(str1,s);
while (token != NULL){
if (strcmp(token,"192.168.3.2") ==0)
{
token = strtok(NULL, s);
printf("Your Physical address is %s",token);
}
else
token = strtok(NULL, s);
}
}
fclose(f1);
return 0;
}
pg. 4
7. AES Encryption Decryption
Note: You need to create PlainTextInput.txt file in D:\ drive of
computer. Execution of program will create EncryptedText.txt and
DecryptedText.txt file in D:\ drive.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.KeyGenerator;
cipher.init(Cipher.ENCRYPT_MODE, key);
CipherInputStream cipt=new CipherInputStream(new
FileInputStream(new File("D:\\PlainTextInput.txt")), cipher);
FileOutputStream fip=new FileOutputStream(new
File("D:\\EncryptedText.txt"));
int i;
while((i=cipt.read())!=-1)
{
fip.write(i);
}
cipher.init(Cipher.DECRYPT_MODE, key);
CipherInputStream ciptt=new CipherInputStream(new
FileInputStream(new File("D:\\EncryptedText.txt")), cipher);
FileOutputStream fop=new FileOutputStream(new
File("D:\\DecryptedText.txt"));
int j;
while((j=ciptt.read())!=-1)
{
fop.write(j);
}
}
catch(Exception e) {
e.printStackTrace();
}
System.out.println("Encryption and Decryption of plain text
file performed successfully.");
}
}
pg. 5
Output of the program:
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *input,*out;
int c,counter=0;
//Source Add
char source[]="192.168.1.1";
//Destination Add
char dest[]="192.168.1.20";
input= fopen("input.txt","r");
out=fopen("output.txt","w");
if(input==NULL){
printf("Input File Not found");
}
else if(out==NULL){
printf("Output file not Created");
}
else{
//Counting No of charecter in files
do{
c=getc(input);
counter++;
}while(c!=EOF);
counter= counter-1;
//Generatting Headers
fprintf(out,"%s,%s,%d",source,dest,counter);
printf("Header generated Successfully.\nCheck output.txt file.");
pg. 6
fclose(input);
fclose(out);
return 0;
}
}
import java.io.*;
import java.net.*;
import java.awt.Desktop;
import java.io.*;
import java.net.*;
System.out.println("File downloaded...");
String url="D:\\index2.htm";
File htmlFile=new File(url);
Desktop.getDesktop().browse(htmlFile.toURI());
bos.close();
sock.close();
}
}
File downloaded...
BUILD SUCCESSFUL (total time: 1 second)
pg. 8
br.close();
writer.close();
System.out.println("Webpage Downloaded Successfully.");
System.out.println("Downloaded file saved as
HomePage.html");
}
catch (MalformedURLException MalurlEx) {
System.out.println("URL Exception raised");
} catch (IOException ie) {
System.out.println("IOException raised");
}
}
Output of program
pg. 9