7 Data Encryption and Decryption Data Encryption Standard Algorithm
7 Data Encryption and Decryption Data Encryption Standard Algorithm
AIM :
To write a C program to implement Data encryption and decryption using Data
Encryption Standard algorithm.
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 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.
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.
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);
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
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