You are on page 1of 6

Exp. No.

: 7 Data encryption and decryption using


Date : Data Encryption Standard algorithm

AIM :
To write a C program to implement Data encryption and decryption using Data
Encryption Standard algorithm.

HARDWARE / SOFTWARE REQUIREMENTS:


 Personal Computer
 Turbo C compiler

THEORY:

Cryptography is the practice and study of techniques for secure communication in the presence
of third parties (called adversaries). More generally, it is about constructing and analyzing protocols that
overcome the influence of adversaries and which are related to various aspects in information security
such as data confidentiality, data integrity, authentication, and non-repudiation.

In cryptography, encryption is the process of encoding messages in such a way that third parties
cannot read it, but only authorized parties can. Encryption doesn't prevent hacking but it prevents the
hacker from reading the data that is encrypted. In an encryption scheme, the message or information is
encrypted using an encryption algorithm, turning it into an unreadable cipher text. This is usually done
with the use of an encryption key, which specifies how the message is to be encoded. Any adversary
that can see the cipher text should not be able to determine anything about the original message. An
authorized party, however, is able to decode the cipher text using a decryption algorithm, that usually
requires a secret decryption key that adversaries do not have access to. For technical reasons, an
encryption scheme usually needs a key- generation algorithm to randomly produce keys.

Kinds of encryption

Symmetric key encryption

Symmetric-key algorithms are a class of algorithms for cryptography that use the same
cryptographic keys for both encryption of plaintext and decryption of cipher text. The keys may be
identical or there may be a simple transformation to go between the two keys. The keys, in practice,
represent a shared secret between two or more parties that can be used to maintain a private information
link. This requirement that both parties have access to the secret key is one of the main drawbacks of
symmetric key encryption, in comparison to public-key encryption. This is also known as private key
encryption. In Symmetric-key schemes, the encryption and decryption keys are the same. Thus,
communicating parties must agree on a secret key before they wish to communicate.

Networks and Security Lab


Public key encryption

Public-key cryptography, also known as asymmetric cryptography, refers to a cryptographic


algorithm which requires two separate keys, one of which is secret (or private) and one of which is
public. Although different, the two parts of this key pair are mathematically linked. The public key is
used to encrypt plaintext or to verify a digital signature; whereas the private key is used to decrypt
cipher text or to create a digital signature. The term "asymmetric" stems from the use of different keys
to perform these opposite functions, each the inverse of the other – as contrasted with conventional
("symmetric") cryptography which relies on the same key to perform both. In public-key encryption
schemes, the encryption key is published for anyone to use and encrypt messages. However, only the
receiving party has access to the decryption key and is capable of reading the encrypted messages.

Working principle:
In cryptography, RC4 is the most widely used software stream cipher and is used in popular protocols
such as Transport Layer Security (TLS) (to protect Internet traffic) and WEP (to secure wireless
networks). While remarkable for its simplicity and speed in software, RC4 has weaknesses that argue
against its use in new systems. It is especially vulnerable when the beginning of the output key stream is
not discarded, or when nonrandom or related keys are used; some ways of using RC4 can lead to very
insecure cryptosystems such as WEP.

Networks and Security Lab


This stream cipher was invented in 1987 by Ron Rivest, one of the inventors of the RSA public
key cryptography algorithm and co-founders of RSA security. Even though the RC4 cipher is named as
"Rivest Cipher 4".

ALGORITHM-ENCRYPTION
Get the text to be encrypted (plain text) and key text.
a. Find the length of the plain text.
b. For i=1 to length of plain text
c. Find the binary equivalent of ith character of plain text.
d. Find the binary equivalent of ith character of key text
e. Find the XOR of above two values.
The resulting value will be the encrypted format (cipher text) of the plain text.

ALGORITHM-DECRYPTION
Get the text to be decrypted (cipher text) and key text.
Find the length of the cipher text.
For i=1 to length of cipher text
a. Find the binary equivalent of ith character of cipher text.
b. Find the binary equivalent of ith character of key text
c. Find the XOR of above two values.
The resulting value will be the decrypted format (original plain text) of the cipher plain text.

Program:

#include <stdio.h>
int main()
{
int i, x;
char str[100];
printf("\nPlease enter a string:\t");
gets(str);

Networks and Security Lab


printf("\n Please choose following options:\n");
printf("1 = Encrypt the string.\n");
printf("2 = Decrypt the string.\n");
scanf("%d", &x);

//using switch case statements


switch(x)
{

case 1:
for(i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] + 3; //the key for encryption is 3 that is added to ASCII value

printf("\nEncrypted string: %s\n", str);


break;

case 2:
for(i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] - 3; //the key for encryption is 3 that is subtracted to ASCII value

printf("\nDecrypted string: %s\n", str);


break;
default:
printf("\nError\n");
}
return 0;
}

Networks and Security Lab


OUTPUT:

Networks and Security Lab


RESULT:
Thus the implementation of Data encryption and decryption using Data Encryption
Standard algorithm is executed and the output is obtained successfully.

Networks and Security Lab

You might also like