Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
468 views

C++ Code

The document describes the Caesar cipher encryption/decryption technique. It begins with an overview of the cipher and how it works by shifting letters in the alphabet by a fixed number, called the key. It then provides pseudocode for encrypting and decrypting messages in C++ using the cipher. It takes a message and key as input, shifts each letter by the key, handles wrapping from z to a, and outputs the encrypted or decrypted message.

Uploaded by

bilisummaa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
468 views

C++ Code

The document describes the Caesar cipher encryption/decryption technique. It begins with an overview of the cipher and how it works by shifting letters in the alphabet by a fixed number, called the key. It then provides pseudocode for encrypting and decrypting messages in C++ using the cipher. It takes a message and key as input, shifts each letter by the key, handles wrapping from z to a, and outputs the encrypted or decrypted message.

Uploaded by

bilisummaa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

C++ Program to Implement Caesar Cypher

to form the Ciphertext. It is a simplest form of substitution cipher scheme.


This cryptosystem is generally referred to as the Shift Cipher. The concept is to replace each
alphabet by another alphabet which is ‘shifted’ by some fixed number between 0 and 25.
For this type of scheme, both sender and receiver agree on a ‘secret shift number’ for shifting the
alphabet. This number which is between 0 and 25 becomes the key of encryption.
The name ‘Caesar Cipher’ is occasionally used to describe the Shift Cipher when the ‘shift of
three’ is used.
Process
In order to encrypt a plaintext letter, the sender positions the sliding ruler underneath the first set
of plaintext letters and slides it to LEFT by the number of positions of the secret shift.
The plaintext letter is then encrypted to the ciphertext letter on the sliding ruler underneath. The
result of this process is depicted in the following illustration for an agreed shift of three
positions. In this case, the plaintext ‘tutorial’ is encrypted to the ciphertext ‘wxwruldo’. Here is
the ciphertext alphabet for a Shift of 3 −

On receiving the ciphertext, the receiver who also knows the secret shift, positions his sliding
ruler underneath the ciphertext alphabet and slides it to RIGHT by the agreed shift number, 3 in
this case.
He then replaces the ciphertext letter by the plaintext letter on the sliding ruler underneath.
Hence the ciphertext ‘wxwruldo’ is decrypted to ‘tutorial’. To decrypt a message encoded with a
Shift of 3, generate the plaintext alphabet using a shift of ‘-3’ as shown below −

Here is the implementation of above process in C++.


Steps and pseudocodes
Take the message and key as input −
For encryption
Input: tutorial.
Output: wxwruldo
For decryption
Input: wxwruldo
Output: tutorial
For encryption
Begin
For i = 0 to msg[i] != '\0'
ch = msg[i]
//encrypt for lowercase letter
If (ch >= 'a' and ch <= 'z')
ch = ch + key
if (ch > 'z')
ch = ch - 'z' + 'a' - 1
done
msg[i] = ch
//encrypt for uppercase letter
else if (ch >= 'A' and ch <= 'Z')
ch = ch + key
if (ch > 'Z')
ch = ch - 'Z' + 'A' - 1
done
msg[i] = ch
done
done
Print Encrypted message
End
For decryption
Begin
For i = 0 to msg[i] != '\0'
ch = msg[i]
//decrypt for lowercase letter
if(ch >= 'a' and ch <= 'z')
ch = ch - key
if (ch < 'a')
ch = ch +'z' - 'a' + 1
done
msg[i] = ch
//decrypt for uppercase letter
else if (ch >= 'A' and ch <= 'Z')
ch = ch + key
if (ch < 'A')
ch = ch + 'Z' - 'A' + 1
done
msg[i] = ch
done
done
Print decrypted message
End
Example
#include<iostream>
#include<string.h>
using namespace std;
int main() {
cout<<"Enter the message:\n";
char msg[100];
cin.getline(msg,100); //take the message as input
int i, j, length,choice,key;
cout << "Enter key: ";
cin >> key; //take the key as input
length = strlen(msg);
cout<<"Enter your choice \n1. Encryption \n2. Decryption \n";
cin>>choice;
if (choice==1) //for encryption{
char ch;
for(int i = 0; msg[i] != '\0'; ++i) {
ch = msg[i];
//encrypt for lowercase letter
If (ch >= 'a' && ch <= 'z'){
ch = ch + key;
if (ch > 'z') {
ch = ch - 'z' + 'a' - 1;
}
msg[i] = ch;
}
//encrypt for uppercase letter
else if (ch >= 'A' && ch <= 'Z'){
ch = ch + key;
if (ch > 'Z'){
ch = ch - 'Z' + 'A' - 1;
}
msg[i] = ch;
}
}
printf("Encrypted message: %s", msg);
}
else if (choice == 2) { //for decryption
char ch;
for(int i = 0; msg[i] != '\0'; ++i) {
ch = msg[i];
//decrypt for lowercase letter
if(ch >= 'a' && ch <= 'z') {
ch = ch - key;
if(ch < 'a'){
ch = ch + 'z' - 'a' + 1;
}
msg[i] = ch;
}
//decrypt for uppercase letter
else if(ch >= 'A' && ch <= 'Z') {
ch = ch - key;
if(ch < 'A') {
ch = ch + 'Z' - 'A' + 1;
}
msg[i] = ch;
}
}
cout << "Decrypted message: " << msg;
}
}
Output
For encryption:
Enter the message:
tutorial
Enter key: 3
Enter your choice
1. Encryption
2. Decryption
1
Encrypted message: wxwruldo

For decryption:
Enter the message:
wxwruldo
Enter key: 3
Enter your choice
1. Encryption
2. Decryption
2
Decrypted message: tutorial
Encrypt and decrypt text file using C++
Encryption in cryptography is a process by which a plain text or a piece of information is
converted into ciphertext or a text which can only be decoded by the receiver for whom the
information was intended. The algorithm that is used for the process of encryption is known as
a cipher. It helps protect consumer information, emails, and other sensitive data from
unauthorized access to it and secures communication networks. Presently there are many options
to choose from and find the most secure algorithm which meets our requirements.
Decryption: Decryption is the process of converting a meaningless message (Ciphertext) into its
original form (Plaintext). It works by applying the conversion algorithm opposite of the one that
is used to encrypt the data. The same key is required to decrypt the information back to its
normal form.
Types of Cryptography: There are two types of cryptography:
Symmetric Cryptography: It is an encryption system where the sender and receiver of a
message use a single common key to encrypt and decrypt messages. Symmetric Key Systems are
faster and simpler, but the sender and receiver have to somehow exchange keys securely. The
most popular symmetric-key cryptography system is Data Encryption System(DES).
Asymmetric Cryptography: Under this system, a pair of keys is used to encrypt and decrypt
information. A public key is used for encryption and a private key is used for decryption. The
public key and the private key are different. Even if the public key is known by everyone, the
intended receiver can only decode it because he alone knows the private key.
In this article, symmetric cryptography is used to encrypt and decrypt data.
Approach: Let’s discuss the approach in detail before proceeding to the implementation part:
A class encdec is defined with two member functions: encrypt() and decrypt(). The name of the
file to be encrypted is the member variable of the class.
encrypt() function is used to handle the encryption of the input file. The file handling code is
included in the encrypt() function to read the file and write to the file. A new encrypted file
called encrypt.txt is generated with all the encrypted data in it. The encrypted file is encrypted
using a key that is being inputted by the user.
decrypt() function is used to read the encrypted file and decrypt the data and generate a new
file decrypt.txt. To decrypt a file, a key is requested from the user. If the correct key is entered,
then the file is successfully decrypted.
The input stream fin is used to read from the file and the output stream fout is used to write to the
file.
Below is the implementation of the above approach:

C++

// C++ program for the above approach

#include <bits/stdc++.h>
#include <fstream>
using namespace std;

// encdec class with encrypt() and


// decrypt() member functions
class encdec {
int key;

// File name to be encrypt


string file = "geeksforgeeks.txt";
char c;

public:
void encrypt();
void decrypt();
};

// Definition of encryption function


void encdec::encrypt()
{
// Key to be used for encryption
cout << "key: ";
cin >> key;

// Input stream
fstream fin, fout;

// Open input file


// ios::binary- reading file
// character by character
fin.open(file, fstream::in);
fout.open("encrypt.txt", fstream::out);

// Reading original file till


// end of file
while (fin >> noskipws >> c) {
int temp = (c + key);

// Write temp as char in


// output file
fout << (char)temp;
}

// Closing both files


fin.close();
fout.close();
}

// Definition of decryption function


void encdec::decrypt()
{
cout << "key: ";
cin >> key;
fstream fin;
fstream fout;
fin.open("encrypt.txt", fstream::in);
fout.open("decrypt.txt", fstream::out);

while (fin >> noskipws >> c) {

// Remove the key from the


// character
int temp = (c - key);
fout << (char)temp;
}

fin.close();
fout.close();
}

// Driver Code
int main()
{
encdec enc;
char c;
cout << "\n";
cout << "Enter Your Choice : -> \n";
cout << "1. encrypt \n";
cout << "2. decrypt \n";
cin >> c;
cin.ignore();

switch (c) {
case '1': {
enc.encrypt();
break;
}
case '2': {
enc.decrypt();
break;
}
}
}

Output:
Video Player
00:00
01:1
#include<iostream>
#include<math.h>
using namespace std;
float en[3][1], de[3][1], a[3][3], b[3][3], msg[3][1], m[3][3];
void getKeyMatrix() { //get key and message from user
int i, j;
char mes[3];
cout<<"Enter 3x3 matrix for key (should have inverse):\n";
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++) {
cin>>a[i][j];
m[i][j] = a[i][j];
}
cout<<"\nEnter a string of 3 letter(use A through Z): ";
cin>>mes;
for(i = 0; i < 3; i++)
msg[i][0] = mes[i] - 65;
}
void encrypt() { //encrypts the message
int i, j, k;
for(i = 0; i < 3; i++)
for(j = 0; j < 1; j++)
for(k = 0; k < 3; k++)
en[i][j] = en[i][j] + a[i][k] * msg[k][j];
cout<<"\nEncrypted string is: ";
for(i = 0; i < 3; i++)
cout<<(char)(fmod(en[i][0], 26) + 65); //modulo 26 is taken for each element of the matrix
obtained by multiplication
}
void inversematrix() { //find inverse of key matrix
int i, j, k;
float p, q;
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++) {
if(i == j)
b[i][j]=1;
else
b[i][j]=0;
}
for(k = 0; k < 3; k++) {
for(i = 0; i < 3; i++) {
p = m[i][k];
q = m[k][k];
for(j = 0; j < 3; j++) {
if(i != k) {
m[i][j] = m[i][j]*q - p*m[k][j];
b[i][j] = b[i][j]*q - p*b[k][j];
}
}
}
}
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++)
b[i][j] = b[i][j] / m[i][i];
cout<<"\n\nInverse Matrix is:\n";
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++)
cout<<b[i][j]<<" ";
cout<<"\n";
}
}
void decrypt() { //decrypt the message
int i, j, k;
inversematrix();
for(i = 0; i < 3; i++)
for(j = 0; j < 1; j++)
for(k = 0; k < 3; k++)
de[i][j] = de[i][j] + b[i][k] * en[k][j];
cout<<"\nDecrypted string is: ";
for(i = 0; i < 3; i++)
cout<<(char)(fmod(de[i][0], 26) + 65); //modulo 26 is taken to get the original message
cout<<"\n";
}
int main() {
getKeyMatrix();
encrypt();
decrypt();
}
Example
#include <iostream>
#include <string>
using namespace std;
class Vig {
public:
string k;
Vig(string k) {
for (int i = 0; i < k.size(); ++i) {
if (k[i] >= 'A' && k[i] <= 'Z')
this->k += k[i];
else if (k[i] >= 'a' && k[i] <= 'z')
this->k += k[i] + 'A' - 'a';
}
}
string encryption(string t) {
string output;
for (int i = 0, j = 0; i < t.length(); ++i) {
char c = t[i];
if (c >= 'a' && c <= 'z')
c += 'A' - 'a';
else if (c < 'A' || c > 'Z')
continue;
output += (c + k[j] - 2 * 'A') % 26 + 'A'; //added 'A' to bring it in range of ASCII alphabet [
65-90 | A-Z ]
j = (j + 1) % k.length();
}
return output;
}
string decryption(string t) {
string output;
for (int i = 0, j = 0; i < t.length(); ++i) {
char c = t[i];
if (c >= 'a' && c <= 'z')
c += 'A' - 'a';
else if (c < 'A' || c > 'Z')
continue;
output += (c - k[j] + 26) % 26 + 'A';//added 'A' to bring it in range of ASCII alphabet [ 65-
90 | A-Z ]
j = (j + 1) % k.length();
}
return output;
}
};
int main() {
Vig v("WELCOME");
string ori ="Thisistutorialspoint";
string encrypt = v.encryption(ori);
string decrypt = v.decryption(encrypt);
cout << "Original Message: "<<ori<< endl;
cout << "Encrypted Message: " << encrypt << endl;
cout << "Decrypted Message: " << decrypt << endl;
}

The Caesar Cipher is a simple substitution cipher named after Julius Caesar, who reportedly
used it to communicate with his officials. The technique involves shifting each letter in a
message by a fixed number of positions in the alphabet. For example, with a shift of 3, A would
be replaced by D, B would become E, and so on.
The Caesar Cipher is relatively easy to break and is considered to be a very weak form of
encryption, but it served its purpose for Julius Caesar. It's still used for educational and
recreational purposes.
Algorithm for Caesar Cipher
Here is a basic algorithm for encoding a message using the Caesar Cipher with a shift of k −
Initialize a variable shift to the value of k.
Iterate through each character c in the message −
If c is a letter (uppercase or lowercase), shift it by shift positions in the alphabet.
To shift an uppercase letter, subtract 'A' from the letter, add the shift value, and take the modulus
26. Then add 'A' back to get the shifted letter.
To shift a lowercase letter, subtract 'a' from the letter, add the shift value, and take the modulus
26. Then add 'a' back to get the shifted letter.
b. Append the shifted letter to the encoded message.
Return the encoded message.
To decode an encoded message, the same algorithm can be used with a shift of -k.
Example
def caesar_cipher_encrypt(plaintext, shift):
ciphertext = ""
for c in plaintext:
if c.isalpha():
ascii_code = ord(c)
if c.isupper():
ascii_code = (ascii_code - ord('A') + shift) % 26 + ord('A')
else:
ascii_code = (ascii_code - ord('a') + shift) % 26 + ord('a')
ciphertext += chr(ascii_code)
else:
ciphertext += c
return ciphertext

def caesar_cipher_decrypt(ciphertext, shift):


plaintext = ""
for c in ciphertext:
if c.isalpha():
ascii_code = ord(c)
if c.isupper():
ascii_code = (ascii_code - ord('A') - shift) % 26 + ord('A')
else:
ascii_code = (ascii_code - ord('a') - shift) % 26 + ord('a')
plaintext += chr(ascii_code)
else:
plaintext += c
return plaintext
Please note that this algorithm is limited and can be broken by a cryptanalyst with relative ease.
it is not recommended to use it in any real-world applications, it's commonly used as a learning
tool in the field of cryptography.
Example
Here is an example of encoding and decoding a message using the Caesar Cipher with a shift of
3−
plaintext = "HELLO WORLD"
shift = 3

ciphertext = caesar_cipher_encrypt(plaintext, shift)


print("Encrypted message:", ciphertext) # Encrypted message: KHOOR ZRUOG

decrypted_text = caesar_cipher_decrypt(ciphertext, shift)


print("Decrypted message:", decrypted_text) # Decrypted message: HELLO WORLD
As you can see, in the first step of the process, the plaintext "HELLO WORLD" is passed to the
caesar_cipher_encrypt function along with the shift value of 3, resulting in the ciphertext
"KHOOR ZRUOG".
In the second step, the previously obtained ciphertext is passed to the caesar_cipher_decrypt
function along with the same shift value, and the original plaintext message is obtained.
Example
plaintext = "hello world"
shift = 2
ciphertext = caesar_cipher_encrypt(plaintext, shift)
print("Encrypted message:", ciphertext) # Encrypted message: jgnnq ytqng
decrypted_text = caesar_cipher_decrypt(ciphertext, shift)
print("Decrypted message:", decrypted_text) # Decrypted message: hello world
As you can see, shift of 2 is used for the encryption and the decryption process, resulting in the
same plaintext message "hello world"
Please note that this is just an example, Caesar Cipher is not secure and should not be used in
real-world applications.
How to decrypt?
The Caesar Cipher is a simple substitution cipher, so the most straightforward way to decrypt an
encoded message is to try different shift values until the decrypted message makes sense. This is
known as a "brute-force" attack.
Here is the basic algorithm for decoding an encoded message using a brute-force attack −
Iterate through all possible shift values, starting from 0 to 25 (since there are 26 letters in the
alphabet).
For each shift value, create a new empty string to hold the decoded message.
Iterate through each character c in the encoded message −
If c is a letter (uppercase or lowercase), shift it back by the current shift value positions in the
alphabet
To shift an uppercase letter back, subtract the current shift value from the letter, add 26 and take
modulus of 26. Then add 'A' back to get the original letter.
To shift a lowercase letter back, subtract the current shift value from the letter, add 26 and take
modulus of 26. Then add 'a' back to get the original letter.
Append the shifted letter to the decoded message.
Print the decoded message along with the shift value used.
Repeat the process until the message makes sense
It's worth mentioning, that more advanced methods such as frequency analysis, pattern
recognition can be used to break the ciphertext much faster than the brute force method.
It is important to note that the Caesar Cipher is very weak, and is not considered secure for use in
modern cryptography. It's commonly used as a learning tool to introduce the concept of
substitution ciphers.

Difference between Block Cipher and Stream Cipher


AlgorithmsAnalysis of AlgorithmsMCA
Both Block cipher and Stream cipher belong to the family of symmetric key ciphers which are
the basically encryption methods primarily used for converting the plaintext into ciphertext
directly.
Go through this article to find out more about the features of block ciphers and stream ciphers
and how they are different from each other.
What is Block Cipher?
A block cipher is a symmetric cryptographic technique that uses a shared, secret key to encrypt a
fixed-size data block. During encryption, plaintext is used, and ciphertext is the resultant
encrypted text. The plaintext and ciphertext are both encrypted using the same key.
A block cipher processes the data blocks of fixed size. Usually, the size of a message is larger
than the block size. Hence, the long message is divided into a series of sequential message
blocks, and the cipher operates on these blocks one at a time.
Using a shared, secret key, a block cipher encrypts and decrypts its input one block rather than
one bit at a time. Padding is not required because the block is fixed in size. This is a symmetric
algorithm. It transforms textual input into cyphertext using the shared key during encryption
(encrypted text). It employs the same key to convert the cyphertext back to the original plaintext
during decryption. The length of the output is the same as the length of the input.
The Data Encryption Standard (DES), TripleDES, and the Advanced Encryption standard are
well-known versions of the block cipher algorithm (AES).
The stream cipher, which uses a shared key and operates on its input one bit at a time, is the
block cipher's counterpart.
Public-key cryptography or asymmetric cryptography are alternatives to the block cipher
algorithm. This algorithm encrypts plaintext with a public key and decrypts the ciphertext with a
private key.
There are different modes of operation of a block cipher −
Electronic Code Book (ECB) Mode
Cipher Block Chaining (CBC) Mode
Cipher Feedback (CFB) Mode
Output Feedback (OFB) Mode
Counter (CTR) Mode
These modes are procedural rules for a generic block cipher. Interestingly, the different modes
result in different properties being achieved which add to the security of the underlying block
cipher.
What is Stream Cipher?
A stream cipher is an encryption method that combines a pseudorandom cipher digit stream with
plain text digits. This pseudorandom encryption digit stream is applied one bit at a time to each
binary digit. This encryption method employs an endless amount of pseudorandom cipher digits
for each key.
A stream cipher employs a key-based algorithm to encrypt an arbitrary amount of plain text one
bit at a time.
The pseudorandom cipher numbers should be unpredictable, and the key should never be used
more than once for this type of encryption to be secure.
The pseudorandom cipher digits are created using digital shift registers and several random seed
values.
Stream cipher is also known as State cipher. The name "state cipher" comes from the fact that
each number's encryption depends on the current state of the cipher.
The RC4 stream cipher is widely used in the software.
With a properly designed pseudorandom number generator, a stream cipher can be as safe as a
block cipher of equal key length. The main advantage of a stream cipher is that it uses far less
code and it is faster than block ciphers.
Difference between Block Cipher and Stream Cipher
The following table highlights the major differences between a block cipher and a stream cipher

Key Block Cipher Stream Cipher

Block Cipher is the type of encryption Stream Cipher is the type of


where the conversion of plaintext is encryption where the conversion
Definition performed by taking its block at a time. of plaintext is performed by
taking one byte of the plaintext at
a time.
Key Block Cipher Stream Cipher

Since Block Cipher converts blocks at a In the case of Stream Cipher,


Conversion of time, it converts a more significant however, only 8 bits can be
Bits number of bits than Stream Cipher, transformed at a time.
which can convert 64 bits or more.

Block Cipher uses both "confusion" and Stream Cipher uses only
Principle "diffusion" principle for the conversion confusion principle for the
required for encryption. conversion.

For encryption of plain text Block Stream Cipher uses CFB (Cipher
Cipher uses Electronic Code Book Feedback) and OFB (Output
Algorithm
(ECB) and Cipher Block Chaining Feedback) algorithm.
(CBC) algorithm.

As a combination of more bits get Stream Cipher uses XOR for the
encrypted in case of Block Cipher, so encryption which can be easily
Decryption the reverse encryption or decryption is reversed to the plain text.
comparatively complex as compared to
that of Stream Cipher.

Feistel Cipher is the most common The main implementation of


Implementation
Block Cipher implementation. Stream Cipher is Vernam Cipher.
Conclusion
Block ciphers are suitable for applications that manage blocks of data including file transfer, e-
mail, and database. Stream ciphers, on the other hand, are more useful for applications that need
to encrypt/decrypt a stream of data, including over a data communications channel or a
browser/Web link.
Stream Cipher
A stream cipher is one that encrypts a digital data flow one bit or one byte at a time. Stream
Cipher generally encrypts one byte of the message at that moment rather than using blocks.
For example, classical stream ciphers are the auto crucial Vigenère cipher and the Vernam
cipher. In the conceptual case, a one-time pad version of the Vernam cipher can be used, in
which the key stream is considering the plaintext bit stream.
If the cryptographic key stream is arbitrary, therefore this cipher is unbreakable by some
different means other than realizing the key stream. However, the key stream should be provided
to both users in advance through some independent and secure channel.
This recommend insurmountable logistical issues if the intended data traffic is very high. The
bit-stream generator should be performed as an algorithmic process, so that the cryptographic bit
flow can be created by both users.
In this method, the bit-stream generator is a key-controlled algorithm and should make a bit
stream that is cryptographically powerful. Now, the two users required only share the generating
key, and each can create the key stream.
Block Cipher
A block cipher is one in which a block of plaintext is considered as a whole and used to create a
cipher text block of same length. Generally, a block size of 64 or 128 bits is used. Block Cipher
takes a message and divide it into a fixed size of blocks and change one block of the message at
an instant.
A block cipher works on a plaintext block of n bits to create a cipher text block of n bits. There
are possible several plaintext blocks and, for the encryption to be changeable (i.e., for decryption
to be possible), each should create a unique cipher text block. Such transformation is also known
as reversible, or non-singular.
Block ciphers are based on mathematical objects known as Pseudo Random Permutations (PRP).
They are invertible functions that create as input an n-bit value m and a secret key k, and output
an n-bit value c.
A PRP is treated secure if, fixed with a key k, the resulting function is identical from a random
bijective function on n-bit values. Block ciphers perform a secure PRP.
They are made of an encryption function that is capable to encrypt a plaintext block into a
ciphertext block using a secret key. A decryption function that implements the inverse operation
and fetch the plaintext block from the ciphertext.
The main difference between stream and block ciphers based on the size of the information that
are handled in each encryption. Stream ciphers encrypt one bit at a time from a bitstream and this
results in the encrypted message having a bit-to-bit agreement with the plaintext message.
What is Block Cipher in information security?
Information SecuritySafe & SecurityData Structure
A block cipher is a set of encryption where plain text is first breaked into several blocks, each
with a fixed size. Essentially, each block has the similar number of data bits. At any given time,
the encryption procedure work on an individual block of plain text and uses the encryption key to
transfer it into a block of ciphertext.
Each block is of the similar size (such as 64 bits). For example, a 160-bit plain text is encoded
into 2 blocks of 64-bits each, while the third block will have the remaining balance of 32 bits. It
will be padded with an extra 32 bits to support the similar size as other blocks.
A block cipher is an encryption approach that uses a deterministic algorithm forward with a
symmetric key to encode a block of text, instead of encoding one bit at a time as in stream
ciphers.
Block ciphers are pseudorandom permutation (PRP) classification that work on the fixed size
block of bits. PRPs are functions that cannot be understand from absolutely random permutations
and therefore, are treated reliable, until proven not true.
A block cipher works on a plaintext block of n bits to create a cipher text block of n bits. There
are possible several plaintext blocks and, for the encryption to be changeable (i.e., for decryption
to be possible), each should create a unique cipher text block. Such transformation is known as
reversible, or non-singular.
Block cipher modes of operation have been produced to remove the chance of encrypting
identical blocks of text the similar method, the ciphertext formed from the previous encrypted
block is used to the next block.
A block of bits known as initialization vector (IV). It can be also used by modes of operation to
provide ciphertexts remain definite even when the similar plaintext message is encrypted a
number of times. A block cipher is a class of cipher that encrypts text by functioning blocks of
the text through an algorithm that assortment it up. This is against a stream cipher that encrypts
text one bit at a time.
For example, a block cipher would operate by encrypting the first paragraph of this lesson before
changing on to the next paragraph.
A block cipher can repeat this phase until the whole lesson was encrypted. A stream cipher can
start by encrypting the first character of the first paragraph before changing on the next character
in the similar paragraph.
This procedure is repeated until the whole lesson is encrypted. Text that has been encrypted by a
cipher is known as ciphertext. It can return the ciphertext back to its original state, it should be
run through the cipher once again.
Data Encryption: Types, Algorithms, Techniques, and Methods
Cyber SecurityAnti VirusSafe & Security
Consider the electronic digital media and the millions of online messages that travel up and
down each day. Like the registered post facility that ensures safe delivery, digital authorities
need reliable methods to ensure privacy and non-interference. Safety measures assume greater
importance in Ecommerce and Banking, where money changes hands. All is not lost, even
though cybercrime is growing with data encryption. Stealing passwords and account numbers
enable fraudsters to misuse hard-earned money. Data encryption refers to the change of plaintext
to scrambled text with a code that is unreadable. Scrambled text is also known as ciphertext.
Decryption means changing the scrambled text back to the original plaintext.
Types of Encryption
Sensing the urgent and severe dangers of misuse of information, such Encryption is applied
everywhere. Encryption works on any kind of document, file, and message. The vast online
networks today contain a great variety of communication methods. Encryption applies to all.
Only some communication channels are so secure. Emails do not carry strict security compared
to defense departments, for instance. Rising cybercrime levels have now resulted in Encryption
being adopted by mega businesses, even smaller organizations, and individuals. Without
Encryption, nothing would be secret, and cybercrime would become very common!
Algorithms for Encryption and decryption
Algorithms of many types represent the mathematical calculations required for Encryption.
Encrypting and decrypting data needs keys, public keys known to everybody, and secret and
private keys. Symmetric methods require a single key known to both sender and recipient.
Asymmetric methods have public and private keys, which ensures greater security levels.
Without the keys, neither sending nor receiving personal data would be possible.
Functions of Encryption
Encrypted data security protects in emergencies like losing a device containing precious
private company data. Encrypted data in the drive remains secure despite being lost or
misplaced. Encryption brings confidence in work and communication since data is relatively
safe. During data transmission and at rest, data breaches cannot occur.
Privacy for personal and official data is assured, which means that illegal access is denied, just
like essential buildings being heavily guarded by sentries with weapons. Even internet service
providers cannot see what the messages contain. Hackers and spammers wish to read the notes,
but they cannot. Encryption makes such a significant difference.
Specific rules need to be followed where personal information is entered. Such data must be
encrypted according to government and industry regulations. GDPR, HIPAA, PCI-DSS, and
organizations like them guide and regulate Encryption.
Valid ownership of data and their origin is validated through the encryption keys that receive an
SSL certificate. In an ocean of websites, such certification indicates authenticity.
2 Data Encryption Techniques
Among the several kinds of Data Encryption Techniques, 3 have gained immense importance -
symmetric, asymmetric, and hashing. There have several types too.
Symmetric Encryption requires a single secret key known to the sender and receiver. This
procedure succeeds in securing systems with fewer dangers of intrusion. This method works fast,
but both sides must take pains to ensure the secrecy of the key.
Asymmetric Encryption uses two keys with mathematical linking, public and private.
Encryption and decryption happen with separate keys for greater safety. Asymmetric means that
the keys are dissimilar with large paired numbers. Everyone knows the public key, but only the
recipient knows the secret key and nobody else.
Hashing indicates an exclusive signature of a certain length that represents a message. Hashing
helps to verify data. Since each message has a different hash, any changes made can be detected.
A hashed message cannot be decoded or reverted to the original state.
Leading Encryption Algorithms Methods
An encryption key transforms the plaintext into scrambled data or ciphertext through the
algorithm. The scrambled data can be changed back to the plaintext with the right decryption
key. Among several different encryption algorithms widely used globally, check out a few
important ones.
Rivest-Shamir-Adleman (RSA)
The RSA robust and trustworthy encryption standard solves numerous data protection issues. An
asymmetric encryption algorithm, RSA factorizes two large prime numbers and their product.
Decoding the message is possible with the two numbers. RSA is important for digital signatures.
A disadvantage is the loss of speed when Encryption concerns mega data.
Triple Data Encryption Algorithm (3DEA)
Usually known as 3DES, the method encrypts data thrice with the Data Encryption Standard
(DES) cipher. Following the symmetric key method, a single key encrypts and decrypts data. It
works proficiently in the Feistel network with exact processes. 3DES was widely used before
AES. 3DES was used for EMV payment systems, Firefox, and Microsoft Office. 3DES probably
will end in 2023 or 2024 because better options have been found.
Advanced Encryption Standard (AES)
Governments and large organizations often use AES, which suits tough encryption tasks. AES
uses 128-, 192- and 256-bit keys. Believed to be unbeatable, brute Force could disrupt it.
Triple DES
After hackers successfully invaded DES, triple DES used the DES algorithm thrice on the data.
Triple DES may gradually disappear though it solved many problems. Triple DES encrypts ATM
PINS and UNIX passwords successfully.
Blowfish
Intended to replace DES, Blowfish is a symmetric tool. It encrypts individual messages through
64-bit blocks. It is fast, pliant, and firm. More attractive since it is free, Blowfish belongs to the
public domain. It is used in E-commerce, password, and payment systems.
Twofish
Following Blowfish, Twofish also has symmetric Encryption and is free of licensing. It can
decipher 128-bit data blocks. It suits software and hardware tasks, encrypting data in 16 rounds,
irrespective of key size. Working very fast, it is the solution for numerous file and folder
encryption tasks of the present day.
Conclusion
Personal devices, emails, attachments, and various documents, large and small, have a savior
called Encryption that ensures privacy. External devices and portable media increase the risk of
data loss, just like networking in public places. Decryption is the final stage of opening the
message into a readable form. While millions of messages are encrypted daily, fraudsters and
hackers are busy with their arsenal. Brute Force tries several keys to open the encrypted message
till one fits. Data loss prevention techniques need to be taken seriously since many dangers
abound from leaks and misuse. The cat-and-mouse game continues with a little bit of luck if
mega data is safe and sound.
What are the techniques of data Encryption?
Information SecuritySafe & SecurityData Structure
There are some techniques of Data Encryption are as follows −
DES − DES stands for Data Encryption Standard. The Data Encryption Standards (DES)
algorithm was invented by IBM in the early 1970s. It accepts the plaintext in 64-bit blocks and
transform it into the ciphertext that need the 64-bit keys to encrypt the information. The
algorithm need the same key to encrypt and decrypt the information.
DES is a symmetric key algorithm can encrypt digital data. Its short key length of 56 bits renders
DES too insecure to secure most current applications that is based on encryption.
Triple DES − Triple DES is also called a TDES. It is a symmetric key block cipher, defining
that the same key is used to encrypt and decrypt information in fixed-length groups of bits
known as blocks. It is known as "Triple DES" because it uses the DES cipher three times when
encrypting information.
RSA − RSA stands for Rivest–Shamir–Adleman. It is termed for the three computer scientists
who produced it to encrypt information in transit in 1977. This public-key encryption
cryptosystem is between the most generally adopted modes of asymmetric cryptography, in part
because of its key length.
RSA’s public key is based on three values such as two very large prime numbers and one other
number that combine to protect the information in transit.
AES − AES is a new cryptographic algorithm that can be used to secure digital information.
Particularly, AES is an iterative, symmetric-key block cipher that can need keys of 128, 192, and
256 bits, and encrypts and decrypts information in blocks of 128 bits (16 bytes).
A Public-key ciphers can use a set of keys, symmetric key ciphers use the similar key to encrypt
and decrypt information. The new AES will certainly develop into the de facto standard for
encrypting all forms of electronic data, restoring DES.
AES-encrypted information is unbreakable in the sense that known cryptanalysis attack can
decrypt the AES cipher text without utilizing a brute-force search through all available 256 bit
keys.
TwoFish − TwoFish is used in both software and hardware applications, uses keys up to 256 bits
in length yet is between the quickest encryption algorithms. This symmetric cipher is also
complimentary and unpatented.
Encryption and SSL − Secure sockets layer (SSL) is a feature of most valid websites, encrypts
information in transit, but not at rest. Data must be encrypted as it is written to disk for some
amount of time, despite the need of SSL technology.
End-to-end encryption (E2EE) − End-to-end encryption define systems in which only the two
users connecting, who both possess keys, can decrypt the communication. This contains the
service provider who cannot access end to end encrypted information.
DES (Data Encryption Standard) - DES Algorithm and Operation
Cyber SecurityAnti VirusSafe & Security
Data Encryption Standard, or DES, is a type of encryption cipher that shields and disguises
sensitive information, so it can't be seen or retrieved by cyberattacks.
DES can be described as a block cipher, encryption/ symmetric -key algorithm. A symmetric key
means the same algorithm/key is used for encryption and decryption. On the other hand,
asymmetric keys use two different keys – one public and the other private, respectively.
History of DES and Current Situation
DES was developed in 1971 by Horst Feistel, a cryptography researcher working at IBM. It was
based on "LUCIFER," the Feistel block cipher, 16 rounds of which made up the DES. 64-bit
blocks of plain text are fed into the DES, which churns out an equivalent 64-bits of ciphertext.
The DES key used for this process is 56-bit in size.
DES was the government's official encryption standard until 2002 when the Advanced
Encryption Standard (AES) routed it in public competitions. The National Institute of Standards
& Technology (NIST), which had first affirmed DES for federal use, now revoked its status for
government use. However, the latest iteration, Triple DES (3DES), has been cleared till 2030 for
sensitive government data. 3DES runs triple the round, so DES, i.e., 48 instead of 16, isn't any
more substantial.
The DES Algorithm and Process
The DES algorithm functions as per the following stages −
Before the encryption process can begin, the 64-bit of plain text is converted into the DES key
size, which is 56 bits. Every 8th bit in the sequence is dropped, and these parity bits help detect
any discrepancies between sets of code. If the plain text is more than 64-bits and is indivisible,
some sequences may be shorter – they are padded with extra bits for processing.
Then the base processes in cryptography − substitution and transposition begin, followed by the
16-stage encryption process.
Stage 1: Initial Permutation
The plain text is first passed through the Initial Permutation (IP). The IP juggles the 64-bit plain
text block and transposes the blocks into each 8th-bit position of the key. The IP then divides the
64-bit block into two halves, i.e., 32-bit half-blocks, known as LPT (Left Plain Text) and RPT
(Right Plain Text).
Stage 2: Encryption
Step 1: Key Transformation
This step is called Compression Permutation - the original 56-bit block that was created is further
compressed into a 48-bit block by discarding some bits. The two 28-bit halves are then permuted
circularly to yield a 48-bit subset.
Step 2: Expansion Permutation
This step is the opposite of Step 1. The two 32-bit halves are expanded into a 48-bit whole. Each
32-bit half is broken down into 8 blocks of 4 bits each. Then 2 more bits from adjoining sides are
attached to the 4-bit blocks, making them 6-bit. The LPT and RPT are now both 48-bit blocks
comprising 8 6-bits each.
Step 3: S-Box Permutation
The Substitution Box permutation/substitution takes the 48-bit RPTs and LPTs and, using a
lookup box, changes the 6-bit parts into a 4-bit output generating a 32-bit output. This phase
supplements the cipher with an extra layer of security.
Step 4: P-Box Permutation
This step involves simply re-shuffling the 32-bit output and sorting them into four separate S-
Boxes.
Step 5: XOR (ExclusiveOR) and Swap
A mathematical function called XOR is applied to the four S-Box sets of bits. The bits can only
be measured as 0 or 1. Two sets of bits are compared to see if they match. Matching at the
smallest bit level strengthens the code.
Stage 3: Combination
Once the encryption is completed, the LPT and RPT sides are re-joined to form the 64-bit
ciphertext.
Stage 4: Final Permutation
The final permutation is done on the 64-bit original block to get the final output, i.e., the 64-bit
ciphertext.
Modes of Operation
We have explored how the DES algorithm functions. Now we look at the different means of
application.
Mode 1: ECB – Electronic Code Book
ECB is the most basic mode of operation. A single DES algorithm is used to encrypt blocks one
at a time. A no different variable is added to the process, making it very simple but easy to
attack, especially via MITM (Man-in-the-Middle).
Mode 2: CBC – Cipher Block Chaining Mode
CBC uses an initialization vector (IV) to incorporate the previous plain text block into the
current one. The chaining process of CBC means that the previous block's input plain text
determines the next one's decryption. The XOR mechanism integrates the current and previous
inputs so that similar cipher texts are not generated.
Mode 3: CFB- Cipher Feedback Mode
The CFB also uses an IV, but the input size (segment) can be varied from a bit to an entire block.
But this time, the previous block's cipher text is integrated into the encryption algorithm as
feedback. This creates a keystream which in turn decides the current next encryption. The XOR
coding function is applied to integrate the keystream, and the current plain text and
pseudorandom outputs are generated.
Mode 4: OFB- Output Feedback Mode
OFB and CFB are very alike. The only difference is that OFB has an additional internal
mechanism that creates a key unrelated to the plain text input and cipher text outputs. The key
creates additional encryption on the entire DES output to create a unique cipher text.
Mode 5: CTR – Counter Mode
The Counter method encrypts each block of plain text and applies an XOR counter. This counter
accumulated incrementally for and as each block is processed.
Conclusion
DES is out of use these days. It cannot withstand brute force attacks from sophisticated code-
cracking technology, and its key length is too short. But studying DES is crucial because it is the
foundation for other encryption standards and algorithms, and it has informed contemporary
cryptography advancements by highlighting the strengths and weaknesses of different
techniques.

You might also like