# Cryptography | DES implementation in C

The Data Encryption Standard (DES) is a symmetric-key algorithm for the encryption of electronic data. Although now considered insecure, it was highly influential in the advancement of modern cryptography.

This article do not cover explanation of DES Algorithm. We suggest to go through very nice tutorial given here for detailed step-by-step explanation.

INPUT FILES TO THE PROGRAM-

input.txt - WILL CONTAIN OUR PLAIN TEXT (Max. Limit of plain text is 64kb).
key.txt - WILL CONTAIN 64-BIT KEY (take below key)

DES implementation –

OUTPUT FILE –
result.txt – IT WILL CONTAIN OUR DECRYPTED TEXT.

TEMP FILES –
bits.txt – IT WILL CONTAIN OUR PLAIN TEXT CONVERTED IN BITS.
cipher.txt – IT WILL CONTAIN OUR ENCRYPTED TEXT IN BITS.
decrypted.txt – IT WILL CONTAIN OUR DECRYPTED TEXT IN BITS (SAME AS bits.txt IN CONTENT)

Above program is tested in Windows environment using Code::Blocks 16.01.

Exercise: Extend the solution to implement 3-DES algorithm.

(2 votes, average: 5.00 out of 5)

Please use our online compiler to post code in comments. To contribute, get in touch with us.
Like us? Please spread the word and help us grow. Happy coding 🙂

Subscribe
Notify of
Guest

I cannot copy the program. I want to test this out in online compiler .
Can you email me this program?

Guest
Kalyan M

i’m unable to execute the program…
While debugging the program …it is showing me these errors…

Line : 504 while (!feof(pt))
Line : 537 create16Keys();

Thanks for your time…

Guest

I am not getting the full plain text, can i know where is the error

Guest

void expansion_function(int pos, int text)
{
for (int i = 0; i < 48; i++)
if (E[i] == pos + 1) \\ could you please explain me this statement ?
EXPtext[i] = text; \\this one
}

int initialPermutation(int pos, int text)
{
int i;
for (i = 0; i < 64; i++)
if (IP[i] == pos + 1)

here also
break;
IPtext[i] = text;
}