Pages

Friday, February 10, 2017

Key generation in Simplified DES

Simplified DES - Key Generation Simulation Program using C Programming


DES means Data Encryption Standard. DES is one of the top cryptographic software security algorithm used for providing security in many information systems. This c programming tutorial will help you to generate secure password (encryption key).

Assumptions for this program: 
  • 10 bits input size
  • Perform Left Shift - 1 (LS-1) on both the halfs
  • Display Key k1 as final output.
#include<stdio.h>
int main()
{
int i, cnt=0, p8[8]={6,7,8,9,1,2,3,4};
int p10[10]={6,7,8,9,10,1,2,3,4,5};

char input[11], k1[10], k2[10], temp[11];
char LS1[5], LS2[5];
//k1, k2 are for storing interim keys
//p8 and p10 are for storing permutation key

//Read 10 bits from user...
printf("Enter 10 bits input:");
scanf("%s",input);
input[10]='\0';

//Applying p10...
for(i=0; i<10; i++)
{
cnt = p10[i];
temp[i] = input[cnt-1];
}
temp[i]='\0';
printf("\nYour p10 key is    :");
for(i=0; i<10; i++)
{ printf("%d,",p10[i]); }

printf("\nBits after p10     :");
puts(temp);
//Performing LS-1 on first half of temp
for(i=0; i<5; i++)
{
if(i==4)
temp[i]=temp[0];
else
temp[i]=temp[i+1];
}
//Performing LS-1 on second half of temp
for(i=5; i<10; i++)
{
if(i==9)
temp[i]=temp[5];
else
temp[i]=temp[i+1];
}
printf("Output after LS-1  :");
puts(temp);

printf("\nYour p8 key is     :");
for(i=0; i<8; i++)
{ printf("%d,",p8[i]); }

//Applying p8...
for(i=0; i<8; i++)
{
cnt = p8[i];
k1[i] = temp[cnt-1];
}
printf("\nYour key k1 is     :");
puts(k1);
//This program can be extended to generate k2 as per DES algorithm.
}

Output of program

Enter 10 bits input:1100011100

Your p10 key is    :6,7,8,9,10,1,2,3,4,5,
Bits after p10     :1110011000
Output after LS-1  :1100110001

Your p8 key is     :6,7,8,9,1,2,3,4,
Your key k1 is     :10001100


You may also like to view following Computer Security Programs:


No comments:

Post a Comment