Friday, February 19, 2016

Simple Hash function implementation on 8 bits using XOR operation.

#include<stdio.h>
int main()
{
char ch, input[9], s[9];
int i, len=0;

printf("Enter your input bits:");
scanf("%s",input);

printf("Enter your key S (8 bits):");
scanf("%s",s);

printf("Your hash code is:");
for(i=0; i<8; i++)
{
ch=input[i]^s[i];
printf("%d",ch);
}
 return 0;
}

Output or program

Enter your input bits:11001100
Enter your key S (8 bits):01010101
Your hash code is:10011001

Program for password decryption using Caesar cipher. (Receiver side)

Caesar Cipher Decryption


//Program for password decryption using Caesar cipher. (Receiver side)
#include<stdio.h>
#include<string.h>
int main()
{
 char password[20];
 int i, len=0;
 
 printf("Enter your encrypted password:");
 scanf("%s",password);
 
 len = strlen(password);
 printf("Your decrypted password is: ");
 
 for(i=0; i<len; i++)
  printf("%c",password[i]-3); 
 
 return 0;
}

Output of the program
Enter your encrypted password:DEFG Your decrypted password is: ABCD
 




Program to encrypt password using Caesar cipher.


Caesar cipher - Password Encryption Practical


#include<stdio.h>
#include<string.h>
int main()
{
char password[20];
int i, len=0;

printf("Enter your password:");
scanf("%s",password);

len = strlen(password);
printf("Your encrypted password is: ");

for(i=0; i<len; i++)
printf("%c",password[i]+3);

return 0;
}

Output of program

Enter your password:ABCD
Your encrypted password is: DEFG

Tuesday, February 16, 2016

C program to validate user input.

//Check marks is in the range of 0 to 100.

#include<stdio.h>
void main()
{
int marks;

printf("Enter marks:");
scanf("%d",&marks);

if(marks > 100 || marks < 0 )
printf("Invalid marks.\nEnter marks in a range of 0-100.");
else
printf("Your marks are %d", marks);
}
/*Output1
Enter marks:80
Your marks are 80
*/

/*Output2
Enter marks:120
Invalid marks.
Enter marks in a range of 0-100.
*/


Use of GOTO statement in C program.

#include<stdio.h>
int main()
{
    int num1=10, num2=20, num3=30;
    printf("%d \n", num1);
    goto ABC;
    printf("%d \n", num2);
    ABC:
    printf("%d \n", num3);
return 0;
}
Output of program:
10
30




You may also like to learn following programs:

Monday, February 15, 2016

C program to write a word in text file.

#include <stdio.h>
#include <string.h>
int main()
{
FILE *fp;
char str[80];
fp = fopen("test.txt", "w+");
printf("Enter your message:");
gets(str);
fprintf(fp, "%s",str);
printf("Your message is written in test.txt file.");
fclose(fp);
//File validation is to be performed...
   return 0;
}


Output of program

Enter your message:hello student
Your message is written in test.txt file.


Thursday, February 11, 2016

C Program to find largest number from given three numbers.

#include<stdio.h>
int main()
{
int num1, num2, num3;

  printf("Enter number1:");
  scanf("%d",&num1);

  printf("Enter number2:");
  scanf("%d",&num2);

  printf("Enter number3:");
  scanf("%d",&num3);

  if(num1 > num2 && num1 > num3)
  {
    printf("Number1 is largest number.");
  }
  if(num2 > num1 && num2 > num3)
  {
    printf("Number2 is largest number.");
  }
  if(num3 > num1 && num3 > num2)
  {
    printf("Number3 is largest number.");
  }
    return 0;
}
/*
Enter number1:5
Enter number2:4
Enter number3:3
Number1 is largest number.
*/
//Note: Add logic to update this program when two/three numbers are same.