Module I-1
Module I-1
Cryptography
It is the science of encrypting and decrypting written communication or
study of encryption principles/encryption.
Crypto – Hidden
Graphy – Writtings
2 parts ie.
1. Plain Text – The original message
2. Cipher Text – Encrypted message
Encrypt, Encipher, Encryption
Converting plain text to cipher text
Decrypt, Decipher, Decryption
Recovering ciphertext from plain text
Terminology
1. Sender & Receiver
The person who wants to send a message to a receiver. Moreover
Sender wants to send the message securely. Sender wants to makes sure
an eavesdropper cannot read the message.
The person who wants to receive the message send by a sender.
2. Message & Encryption
A message is a plaintext or cleartext which converts to ciphertext.
Encryption is the process of hiding or converting a plaintext
message into cipher text using certain encryption algorithms.
An encrypted message is ciphertext
Decryption is the process of converting ciphertext into a plaintext.
Substitution Cipher
In a Substitution cipher, any character of plain text from the given fixed
set of characters is substituted by some other character from the same set
depending on a key. For example with a shift of 1, A would be replaced by B, B
would become C, and so on.
Special case of Substitution cipher is known as Caesar cipher where the
key is taken as 3.
Mathematical representation
The encryption can be represented using modular arithmetic by first
transforming the letters into numbers, according to the scheme, A = 0, B = 1,…,
Z = 25. Encryption of a letter by a shift n can be described mathematically as.
Examples:
Plain Text: I am studying Data Encryption
Key: 4
Output: M eq wxyhCmrk Hexe IrgvCtxmsr
Decryption
To decipher it, the recipient has to work out the column lengths by dividing the
message length by the key length.
Then, write the message out in columns again, then re-order the columns by
reforming the key word.
Simple XOR in Cryptography
XOR is exclusive-or operation: ‘^’ in C or • in mathematical notation. It’s a
standard operation on bits:
0•0=0
0•1=1
1•0=1
1•1=0
Also note that:
a•a=0
a•b•b=a
The simple-XOR algorithm is really an embarrassment; it’s nothing more than a
Vigenère polyalphabetic cipher. It’s here only because of its prevalence in
commercial software packages, at least those in the MS-DOS and Macintosh
worlds [1502,1387]. Unfortunately, if a software security program proclaims
that it
has a “proprietary” encryption algorithm—significantly faster than DES—the
odds
are that it is some variant of this.
/* Usage: crypto key input_file output_file */
void main (int argc, char *argv[])
{
FILE *fi, *fo;
char *cp;
int c;
if ((cp = argv[1]) && *cp!='\0') {
if ((fi = fopen(argv[2], “rb”)) != NULL) {
if ((fo = fopen(argv[3], “wb”)) != NULL) {
while ((c = getc(fi)) != EOF) {
if (!*cp) cp = argv[1];
c ^= *(cp++);
putc(c,fo);
}
fclose(fo);
}
fclose(fi);
}
}
}
This is a symmetric algorithm. The plaintext is being XORed with a keyword to
generate the ciphertext. Since XORing the same value twice restores the
original,
encryption and decryption use exactly the same program:
P•K=C
C•K=P
There’s no real security here. This kind of encryption is trivial to break, even
without computers [587,1475]. It will only take a few seconds with a computer.
Assume the plaintext is English. Furthermore, assume the key length is any
small
number of bytes. Here’s how to break it:
1. Discover the length of the key by a procedure known as counting
coincidences [577]. XOR the ciphertext against itself shifted various
numbers of bytes, and count those bytes that are equal. If the displacement is
a multiple of the key length, then something over 6 percent of the bytes will
be equal. If it is not, then less than 0.4 percent will be equal (assuming a
random key encrypting normal ASCII text; other plaintext will have different
numbers). This is called the index of coincidence. The smallest
displacement that indicates a multiple of the key length is the length of the
key.
2. Shift the ciphertext by that length and XOR it with itself. This removes
the key and leaves you with plaintext XORed with the plaintext shifted the
length of the key. Since English has 1.3 bits of real information per byte (see
Section 11.1), there is plenty of redundancy for determining a unique
decryption.
XOR Gate
The XOR or Exclusive OR Gate is a special type of logic gate used in digital
electronics to perform the exclusive OR operation. There is a logic circuit called
XOR Gate that takes two inputs and produces an output which is the result of
the exclusive OR operation performed on the combination of inputs. This logic
gate produces a high or logic 1 output when both of the inputs are dissimilar,
otherwise, it produces a logic 0 output.
Operations of XOR Gate
We can explain the operation of the XOR gate as follows:
Returns 1, if the number of logical high input is odd.
Returns 0, if number of logical high input is even.
Say we have two inputs, A and B and the output is called X, then the expression
is:
The Boolean expression of XOR Gate is as follows:
X=A’B+AB’
Symbol of XOR Gate
The logic symbol of XOR gate is shown in the following figure. In this figure,
the variables A and B represent the input lines and is the output of the XOR
gate.
One Time Pads
One Time Pad algorithm is the improvement of the Vernam Cipher, proposed by
An Army Signal Corp officer, Joseph Mauborgne. It is the only available
algorithm that is unbreakable(completely secure). It is a method of encrypting
alphabetic plain text. It is one of the Substitution techniques which converts
plain text into ciphertext. In this mechanism, we assign a number to each
character of the Plain-Text.
The two requirements for the One-Time pad are
The key should be randomly generated as long as the size of the message.
The key is to be used to encrypt and decrypt a single message, and then it is
discarded.
So encrypting every new message requires a new key of the same length as the
new message in one-time pad.
The ciphertext generated by the One-Time pad is random, so it does not have
any statistical relation with the plain text.
Security of One-Time Pad
If any way cryptanalyst finds these two keys using which two plaintext are
produced but if the key was produced randomly, then the cryptanalyst cannot
find which key is more likely than the other. In fact, for any plaintext as the size
of ciphertext, a key exists that produces that plaintext.
So if a cryptanalyst tries the brute force attack(try using all possible keys), he
would end up with many legitimate plaintexts, with no way of knowing which
plaintext is legitimate. Therefore, the code is unbreakable.
The security of the one-time pad entirely depends on the randomness of the key.
If the characters of the key are truly random, then the characters of the
ciphertext will be truly random. Thus, there are no patterns or regularities that a
cryptanalyst can use to attack the ciphertext.
Advantages
One-Time Pad is the only algorithm that is truly unbreakable and can be used
for low-bandwidth channels requiring very high security(ex. for military uses).
Disadvantages
There is the practical problem of making large quantities of random keys. Any
heavily used system might require millions of random characters on a regular
basis.
For every message to be sent, a key of equal length is needed by both sender
and receiver. Thus, a mammoth key distribution problem exists.
A one-time pad is nothing more than a large nonrepeating set of truly random
key letters, written on sheets of paper, and gluedtogether in a pad. In its original
form, it was a one-time tape for teletypewriters.The sender uses each key letter
on the pad to encrypt exactly one plaintext character.
Encryption is the addition modulo 26 of the plaintext character and theone-time
pad key character. Each key letter is used exactly once, for only one message.
The sender encrypts the message and then destroys the used pages of the pad or
used section of the tape.
The receiver has an identical pad and uses each key on the pad, in turn, to
decrypt
each letter of the ciphertext. The receiver destroys the same pad pages or tape
section after decrypting the message. New message—new key letters. For
example,
if the message is:
ONETIMEPAD
and the key sequence from the pad is
TBFRGFARFM
then the ciphertext is
IPKLPSFHGQ
because
O + T mod 26 = I
N + B mod 26 = P
E + F mod 26 = K
etc.
Computer Algorithms
There are many cryptographic algorithms. These are three of the most common:
DES (Data Encryption Standard) is the most popular computer encryption
algorithm. DES is a U.S. and international standard. It is a symmetric
algorithm; the same key is used for encryption and decryption.
RSA (named for its creators—Rivest, Shamir, and Adleman) is the most
popular public-key algorithm. It can be used for both encryption and
digital signatures.
DSA (Digital Signature Algorithm, used as part of the Digital Signature
Standard) is another public-key algorithm. It cannot be used for
encryption, but only for digital signatures.
Cryptographic Protocols
A protocol is a series of steps, involving two or more parties designed
to complete a task.
Everyone involved in the protocol must know the protocol and all of
the steps to follow in advance.
Everyone involved in the protocol must agree to follow it.
The protocol must be unambiguous each step must be well defined
and there must be no chance of a misunderstanding.
The protocol must be complete; there must be a specified action for
every possible situation.
A cryptographic protocol is a protocol that uses cryptography.
A cryptographic protocol involves some cryptographic algorithm, but
generally the goal of the protocol is something beyond simple secrecy.
Protocols are divided into 3 Types
1. Arbitrated Protocol
2. Adjudicated Protocol
3. Self-Enforcing Protocol
1. Arbitrated Protocol
An Arbitrator is a disinterested 3 rd party trusted to complete a
protocol.
Disinterested means that the arbitrator has no vested interest in the
protocol and no particular allegiance to any of the parties involved.
Trusted means that all people involved in the protocol accept what he
says as true, what he does as correct, and that he will complete his part
of the protocol.
A person who does not involve in a protocol but he helps to complete
the protocol – Arbitrator.
2. Adjudicated Protocol
Arbitrated protocols can be subdivided into two lower-level
subprotocols.
1. Non – Arbitrated Sub Protocol
One is a non-arbitrated subprotocol, executed every time
parties want to complete the protocol.
3. Self-Enforcing Protocols
A self-enforcing protocol is the best type of protocol.
The protocol itself guarantees fairness.
No arbitrator is required to complete the protocol.
No adjudicator is required to resolve disputes.
If one of the parties tries to cheat, the other party immediately detects
the cheating and the protocol stops. Whatever the cheating party hoped
would happen by cheating, doesn’t happen.
In the best of all possible worlds, every protocol would be self-
enforcing. Unfortunately, there is not a self-enforcing protocol for every
situation.
2. Active attack
Someone who directly involved or not.
He could try to alter the protocol to his own advantage.
He could be pretend to the someone else, introduce new
messages delete existing message or data.
Alter stored information in the computer.
An attacker can destroy the protocol.
Communication using Symmetric Cryptography
Same keys are used for encryption & decryption.
Both sender and receiver use a common key to encrypt and decrypt the
messages.
Key is only known to the sender and receiver.
Before starting the communication sender & receiver shares the secret
key.
This secret key shared through some external means.
At sender side, sender encrypts the message using his copy of the key.
The cipher text is then sent to the receiver over the communication
channel.
At receiver side, receiver decrypts the cipher text using his copy of the
key.
After decryption, the message converts back into readable format.
Regularly using algorithms are DES (56 bit), 3DES, AES (128 bits).
Each algorithm uses certain bit length.
It uses 2 types of cipher i.e.
a. Block Cipher
A block cipher takes a block of plaintext bits and generates a
block of ciphertext bits, generally of same size.
The size of block is fixed in the given scheme. The choice of
block size does not directly affect to the strength of
encryption scheme.
The strength of cipher depends up on the key length.
b. Stream Cipher
In stream cipher, one byte is encrypted at a time while in
block cipher ~128 bits are encrypted at a time. Initially, a
key(k) will be supplied as input to pseudorandom bit
generator and then it produces a random 8-bit output which
is treated as keystream.
The resulted keystream will be of size 1 byte, i.e., 8 bits.
Stream ciphers are fast because they encrypt data bit by bit
or byte by byte, which makes them efficient for encrypting
large amounts of data quickly.
Symmetric encryption is also called secret key encryption, as the key
must be kept secret from third parties.
It also known as private key cryptography.
Eg:
(1) Alice and Bob agree on a cryptosystem.
(2) Alice and Bob agree on a key.
(3) Alice takes her plaintext message and encrypts it using the
encryption algorithm and the key. This creates a ciphertext message.
(4) Alice sends the ciphertext message to Bob.
(5) Bob decrypts the ciphertext message with the same algorithm and
key and reads it.
Communication using Asymmetric Cryptography
A pair of keys is used i.e. one private key and one public key.
Public key is shared and private key will be kept secret.
Public key is used to encrypt the data.
Private key is used to decrypt the data.
Security depends upon the length of key.
Sender encrypts message using receiver’s public key and
receiver decrypt using receiver’s private key.
It is also known as public-key cryptography.
Key pairs are generated with cryptographic algorithm based on
mathematical problems termed one way function.
Key Components
Plaintext: This refers to the original, readable message or data that is
inputted into the encryption algorithm.
Encryption algorithm: This algorithm transforms the plaintext in various
ways.
Public and private keys: A pair of keys chosen so that if one is used for
encryption, the other is used for decryption. The specific transformations
performed depend on whether the public or private key is provided as
input.
Ciphertext: The encrypted, scrambled message produced as output. It can
be find using both the plaintext and the key, but uf there are different keys
then it will give different ciphertexts for the same message or plaintext.
Decryption algorithm: This algorithm takes the ciphertext and the
corresponding key and retrieves the original plaintext.
Eg;
(1) Alice and Bob agree on a public-key cryptosystem.
(2) Bob sends Alice his public key.
(3) Alice encrypts her message using Bob’s public key and sends it to Bob.
(4) Bob decrypts Alice’s message using his private key.
One-Way Functions (Hash Function)
One-way function is applied to generate hash code/value.
In a One-way Function, Input takes as a variable length and it convert into a
fixed length output i.e. a hash value.
It is public key cryptography.
Hash function represented as H.
Fixed length hash value represented as h.
h = H(M)
The kind of hash function algorithm needed for security application –
Cryptographic Hash Function.
Pseudo-Random Sequences
The problem is still those weird correlations and strange results. Every
pseudo-random-sequence generator is going to produce them if you use them
in a certain way. And that’s what a cryptanalyst will use to attack the system.