CSCL unit 1
CSCL unit 1
CSCL unit 1
CSE~Cyber Security
(Mandatory Course)
Faculty: K. Gnaneshwar
Dept. of CSE~CS,
SNIST
Course Objectives:
11
Other Security domains and Cybersecurity
12
Cyber security Fundamentals –
Confidentiality, Integrity, Availability (CIA)
Confidentiality - preventing the disclosure of data to
unauthorized parties.
Also keep the identity of authorized parties involved in
sharing and holding data private and anonymous.
18
Deliberate Attack Motivation
1. Political motivations: examples include destroying,
disrupting, or taking control of targets; making political
statements, protests, or retaliatory actions.
20
Active Attack What is it?
Name
Masquerade: stolen login IDs and passwords, through finding security gaps in programs
or through bypassing the authentication mechanism.(mail received from
attacker but shown from sender)
Session replay A hacker steals an authorized user’s login information by stealing the
session ID. The intruder gains access and the ability to do anything the
authorized user can do on the website
Passive attacks:
Passive attacks are relatively scarce from a classification perspective, but
can be carried out with relative ease, particularly if the traffic is not
encrypted.
Types of passive attacks:
22
Diffe.b/w active and passive attacks
Active attacks, Passive attacks, Software attacks, hardware attacks
24
Virus
A virus is a program that attempts to damage a computer system and
replicate itself to other computer systems.
• virus Requires a host to replicate and usually attaches itself to a host file or a
hard drive sector.
• Replicates each time the host is used.
• Often focuses on destruction or corruption of data.
• Usually attaches to files with execution capabilities such as .doc, .exe, and .bat
extensions.
• Often distributes via e-mail. Many viruses can e-mail themselves to everyone
in your address book.
• Examples: Stoned, Michelangelo, Melissa, I Love You.
Worm
A worm is a self-replicating program that can be designed to do any number of
things, such as delete files or send documents via e-mail. A worm can
negatively impact network traffic just in the process of replicating itself.
2. Modular Exponentiation:
It involves calculating ‘a^b mod n,’ where ‘a’ is the base, ‘b’ is the exponent, and ’n’ is the
modulus. This operation allows for efficient and secure encryption and decryption of
messages.
3. Hash Functions:
These functions often employ modulo arithmetic to map an input to a fixed-size output. By
applying the modulo operator to the result, the output remains within a specified range,
making it suitable for cryptographic applications.
4. Cryptographic Protocols:
Many cryptographic protocols, such as the Diffie-Hellman key exchange and the Digital
Signature Algorithm (DSA), rely on modulo arithmetic to establish secure communication
channels and verify the authenticity of messages.
5. Cryptographic Primitives:
In symmetric encryption algorithms like AES (Advanced Encryption Standard), modulo
operations are used within the algorithm to ensure that encryption and decryption
processes are reversible and secure.
• Let us learn the mechanism behind
the RSA algorithm : • Now we are ready with our
Generating Public Key: – Public Key ( n = 3127 and e
Select two prime no's.
= 3) and Private Key(d =
Suppose P = 53 and Q = 59.
Now First part of the Public key : 2011) Now we will
n = P*Q = 3127. encrypt “HI”:
We also need a small exponent e : • Convert letters to numbers :
But e Must be An integer.
Not be a factor of Φ(n). H = 8 and I = 9
1<e< Thus Encrypted Data c =
Φ(n) [Φ(n) is discusse (pow(89,e)mod n
d below],
Thus our Encrypted Data
Let us now consider it to be equal to 3 comes out to be 1394
.
Now we will decrypt 1394 :
Our Public Key is made of n and e Decrypted Data =
(cd)mod n
>> Generating Private Key:
Thus our Encrypted Data
We need to calculate Φ(n) :
Such that Φ(n) = (P-1)(Q-1) comes out to be 89
so, Φ(n) = 3016 8 = H and I = 9 i.e. "HI".
Now calculate Private Key, d :
d = (k*Φ(n) + 1) / e for some integer k
Mathematical background for Cryptography (The greatest common divisor)
• In cryptography, GCD (Greatest Common Divisor) plays a role in various algorithms and
cryptographic protocols, particularly those based on number theory. Here are a few areas
where GCD is relevant:
• RSA Encryption: In RSA encryption, the security of the algorithm relies on the difficulty of
factoring large composite numbers. The RSA public key consists of two large prime
numbers, and the security of the encryption depends on these primes being kept secret.
GCD calculations are often used in RSA key generation to ensure that the public and private
keys are properly constructed.
• Diffie-Hellman Key Exchange: In the Diffie-Hellman key exchange protocol, two parties can
agree on a shared secret over an insecure communication channel. The security of this
protocol relies on the difficulty of the discrete logarithm problem. GCD calculations are
involved in certain steps of the protocol to ensure the security of the shared secret.
• Primality Testing: GCD calculations can be used in primality testing algorithms, which are
essential for generating large prime numbers used in various cryptographic applications.
For example, the Miller-Rabin primality test involves GCD computations as part of its
probabilistic primality testing process.
• Overall, GCD calculations are a fundamental aspect of many cryptographic algorithms and
protocols, helping to ensure the security and integrity of encrypted communications and
digital transactions.
• What is Euclidean Algorithm?(To find GCD of 2 no.s )
Euclidean Algorithm is one of the oldest algorithms that
was published around 300 BC which is based on the
principle that the GCD of two numbers does not change
if the larger number is replaced by its difference with the
smaller number, i.e.,
• Examples of Euclidean Algorithm
• Find the GCD of 48 and 18.
• 48 = 18 * 2 + 12
• 18 = 12 * 1 + 6
• 12 = 6 * 2 + 0
• Hence, the GCD(48, 18) = 6.
Using GCD and Modulo arithmetic in cryptography (Example java program
/*package whatever //do not write package name here */ // Finding the other part of public key.
import java.io.*; // double e stands for encrypt
import java.math.*; double e = 2;
import java.util.*; double phi = (p - 1) * (q - 1);
/* Java program for RSA asymmetric cryptographic algorithm.
For demonstration, values are relatively small compared to while (e < phi) {
practical application */
/* e must be co-prime to phi and smaller than phi. */
public class GFGF {
if (gcd(e, phi) == 1)
public static double gcd(double a, double h)
break;
{
else
/* This function returns the gcd or greatest common
e++;
divisor */
}
double temp;
int k = 2; // A constant value
while (true) {
double d = (1 + (k * phi)) / e;
temp = a % h;
// Message to be encrypted
if (temp == 0)
double msg = 12;
return h;
System.out.println("Message data = " +
a = h; msg);
h = temp; // Encryption c = (msg ^ e) % n
} double c = Math.pow(msg, e);
} c = c % n;
public static void main(String[] args) System.out.println("Encrypted data = " +
{ c);
double p = 3;
double q = 7; // Decryption m = (c ^ d) % n
double m = Math.pow(c, d);
// Stores the first part of public key: m = m % n;
double n = p * q; System.out.println("Original Message Sent = " + m);
}
}
Chinese remainder theorem
The Chinese Remainder Theorem (CRT) is a fundamental result in number theory, particularly in the field of
modular arithmetic. It provides a solution to a system of simultaneous congruences(when two things are
similar)which are equations expressing that two numbers have the same remainder when divided by another
number.
overview of the Chinese Remainder Theorem:
x≡a1(mod m1)
x≡a2(mod m2)
…..
……
x≡an(mod mn)
where m1,m2,...,mnare pair wise co prime (i.e., their greatest common divisors are all 1) and a1,a2,...,anare
any integers.
The Chinese Remainder Theorem states that there exists a unique solution for x modulo the product of the modulo
m1⋅m2...
⋅ ⋅mn, denoted as M.
Moreover, the solution x can be found using the formula:
X ≡ (∑ i=1 to nai⋅ Mi⋅ Ni) (mod M)
where:
M = m1⋅m2...
⋅ ⋅mn
Mi = M/mi
Niis the modular inverse of Mimodulo mi
The Chinese Remainder Theorem has numerous applications in various areas of mathematics and computer science,
including cryptography, error-correcting codes, and even in solving systems of linear congruences in number
theory. It's an essential tool in solving problems involving modular arithmetic and finding solutions in certain
algebraic structures.
•
Consider the following example for chinese remainder theorem.
Ninj has a friend, Alice, who has a secret number she wants to share with him. But instead of giving the number
directly, she decided to give him the remainder of the number when divided by two different factors, say 5 and
7. Let's say her number has a remainder of 1 when divided by 5 and a remainder of 2 when divided by 7
To find the number, Ninja can use the Chinese Remainder Theorem to combine the remainders in a certain way
to get a unique solution that satisfies both equations.
The equation that he can form from this will be:
X ≅ 1 (mod 5)
X ≅ 2 (mod 7)
X is Alice’s secret number.
Before moving to the solution, try to find X yourself so the concept of the Chinese Remainder Theorem will be
clear to you.
• Finding Zi for Mi:
Here,
– M1Z1 ≅ 1(mod m1)
y1 = 1, y2 = 2
M1Z1 ≅1(mod m1)
m1 = 5, m2 = 7 7*Z1 ≅1(mod 5) 1
Calculating M: Z1 = 3
M = m1*m2
=5*7 – M2Z2 ≅ 1(mod m2)
= 35
5*Z2 ≅1(mod 7) 1
Finding Mi: Z2 = 3
M₁ = M / m1
= m2 (here, M = m1*m2 / m1) • Calculating X:
=7 X = (y1 * Z1 * M1 + y2 * Z2 * M2) mod M
M₂ = M / m2 = (1 * 3 * 7 + 2 * 3 * 5) mod 35
= (21 + 30) mod 35
= m1 (here, M = m1*m2 / m2) = (51) mod 35
=5 = 16
So, Alice’s number was 16.
To solve this modular equation, we can try each integer from 0 to 4 and find which one
satisfies the equation:
7×0≡0mod 5
7×1≡7≡2mod 5
7×2≡14≡4mod 5
7×3≡21≡1mod 5
7×4≡28≡3mod 5
So, the solution is x=3.
• Useful Algebraic Structures in cryptography
• Algebraic structures play a crucial role in cryptography, providing a framework for designing and
analyzing cryptographic algorithms. Here are some useful algebraic structures in cryptography:
1. Groups: Groups are fundamental algebraic structures used in various cryptographic protocols. They
consist of a set of elements and an operation (often denoted as multiplication or addition) that
satisfies closure, associativity, identity, and invertibility properties. In cryptography, groups are
often used in protocols like Diffie-Hellman key exchange and elliptic curve cryptography.
2. Rings and Fields: Rings and fields are algebraic structures that extend the concept of groups. A ring
is a set equipped with two operations (usually addition and multiplication) that satisfy certain
properties, while a field is a ring with the additional property that every nonzero element has a
multiplicative inverse. Modular arithmetic, which is widely used in cryptography, is based on rings
and fields.
3. Finite Fields: Finite fields, also known as Galois fields, are fields with a finite number of elements.
They are extensively used in cryptographic algorithms such as AES (Advanced Encryption
Standard), where finite field arithmetic is employed to achieve cryptographic operations efficiently.
4. Vector Spaces: Vector spaces are algebraic structures consisting of a set of elements called vectors,
along with operations of addition and scalar multiplication. In cryptography, vector spaces are
utilized in various algorithms, such as error-correcting codes and lattice-based cryptography.
5. Algebraic Structures on Elliptic Curves: Elliptic curve cryptography (ECC) is based on the algebraic
structure of elliptic curves defined over finite fields. Elliptic curves provide a group structure that
forms the basis for cryptographic primitives like elliptic curve Diffie-Hellman (ECDH) key exchange
and elliptic curve digital signature algorithm (ECDSA).
6 . Algebraic Structures on Lattices: Lattice-based cryptography relies on the
algebraic structure of lattices, which are discrete additive subgroups of
vector spaces. Lattices are used in cryptographic schemes such as lattice-
based encryption, digital signatures, and homomorphic encryption.
Confidentiality
• Cryptography protects the secrecy of information. Even if the transmission or storage medium has been
compromised, the encrypted information will be render useless to unauthorized person.
Integrity
• Cryptography ensures the information has not been tampered with using hashing method.
Authenticity
• Cryptography ensures the information sent is from intended and not fake sender. This done using digital
certificate, digital signature and Public Key Infrastructure (PKI).
• Cryptography can be further divided into:
• Symmetric (or Secret Key) Cryptography
• Asymmetric (or Public Key) Cryptography
What is Symmetric Cryptography?
In symmetric cryptography, both sender and receiver uses the same secret key to encrypt and decrypt a message.
The most widely used symmetric algorithm is AES (Advanced Encryption Standard )-128, AES-192, and AES-256.
All AES algorithms uses the block size of 128-bit but different size of key lengths (128, 192, 256).
What is Asymmetric Cryptography?
Asymmetric cryptography uses a key pairs — public and private key. It works in a way, message encrypted with
either public or private key can only be decrypted using the other key of the pair. That is public key to
encrypt, private key to decrypt and private key to encrypt, public key to decrypt. Public keys are
disseminated in public network whereas private keys are only known to the owners. This key pair
cryptography differs from symmetric cryptography which uses one secret key.
Some of the algorithms includes RSA(Rivest, Shamir, Adleman), Diffie-Helman key exchange, etc.
Asymmetric Cryptography has 2 usages, data encryption and digital signature.
Basics of cryptography
secreate cryptography
Elementary substitution ciphers are simple methods of encryption where each letter in
the plaintext is replaced with another letter according to a fixed system.
The most well-known substitution cipher is the Caesar cipher, where each letter in the
plaintext is shifted a certain number of places down or up the alphabet.
Another example is the Atbash cipher, where each letter is replaced with its reverse in
the alphabet:
• Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
• Cipher: ZYXWVUTSRQPONMLKJIHGFEDCBA
• So, "HELLO" would be encrypted as "SVOOL" using the Atbash cipher.
These are just two examples of elementary substitution ciphers, but there are many other
types, each with its own method of encryption.
Elementary transposition ciphers
Elementary transposition ciphers involve rearranging the letters of a message according to a
certain system or key.
Both of these ciphers are relatively easy to implement and can be fun to use for simple encryption
tasks, though they are not particularly secure against modern cryptographic techniques.
Transposition Techniques
• Looking at the image, you would get it why it got named rail fence because
it appears like the rail fence.
• first half of cipher text will be:
memtmro
• second row of the rail fence, we will get the second half of the cipher text:
eteoorw
• Now, to obtain the complete cipher text combine both the halves of cipher
text and the complete cipher text will be:
• Cipher Text: M E M T M R O E T E O O R W
Columnar Transposition
• The columnar transposition cipher is more complex as compared to the rail fence. The steps to obtain
cipher text using this technique are as follow:
• Step 1: The plain text is written in the rectangular matrix of the initially defined size in a row by row
pattern.
• Step 2: To obtain the cipher text read the text written in a rectangular matrix column by column. But
you have to permute the order of column before reading it column by column. The obtained message is
the cipher text message.
• To understand the columnar transposition let us take an example:
• Plain text: cyber security
• Now, put the plain text in the rectangle of a predefined size. For our example, the predefined size of the
rectangle would be 5x3. As you can see in the image below the plain text is placed in the rectangle of
5x3. And we have also permuted the order of the column.
c y b e r b c y r e
• 1 2 3 4 5 3 1 2 4 5
s e c u r c s e r u
i t y - - y i t - -
• Now, to obtain the cipher text we have to read the plain text column by column as the sequence of
permuted column order. So, the cipher text obtained by the columnar transposition technique in this
example is:
Book Cipher or Running Key Cipher
Product ciphers are a type of secret key cryptography where the encryption and
decryption process involves multiple rounds of substitution and permutation
operations.
The basic idea is to repeatedly apply these operations to transform the plaintext
into cipher text and vice versa.
One of the advantages of product ciphers is that they can provide a high level of
security by using multiple rounds of encryption, which makes it difficult for
attackers to decrypt the cipher text without knowing the secret key. Additionally,
the use of both substitution and permutation operations adds complexity to the
encryption process, making it harder for attackers to analyze and break the cipher.
• However, product ciphers can also be computationally
intensive, especially if they involve a large number of
rounds or complex encryption algorithms. Additionally,
their security depends heavily on the strength of the
underlying encryption algorithms and the secrecy of the
key used for encryption.
NextAsubstitution
B C D E F G H I J K L M N O P Q R S T U V WX Y Z
Z Y X WV U T S R Q P O N M L K J I H G F E D C B A
LHEOLRWODL
OSVLOIDLWO
The DES algorithm operates on blocks of data and uses a fixed-length key
of 56 bits .
DES published by the National Institute of Standards and Technology
(NIST).
DES is a block cipher, and encrypts data in blocks of size of 64 bit each,
means 64 bits of plain text goes as the input to DES, which produces 64 bits
of cipher text. The same algorithm and key are used for encryption and
decryption, with minor differences. The key length is 56 bits.
since 8 bytes of the 64 bits of the key are not used by the encryption
algorithm (function as check bits only). General Structure of DES is
depicted in the following illustration −
General Structure of DES is depicted in the following illustration −
Round Function
The Data Encryption Standard (DES)
Initial Permutation (IP): The plaintext block is permuted according to a fixed table.
Key Schedule: The 56-bit key is expanded into sixteen 48-bit round keys, one for each round of
encryption.
Round Function: Each round of DES consists of several operations, including expansion,
substitution, permutation, and XOR with the round key.
Final Permutation (FP): The output of the last round is permuted according to a fixed table to
produce the cipher text.
The round function is the heart of the DES algorithm and includes the following steps:
• Expansion: The 32-bit half-block is expanded to 48 bits using a fixed permutation table.
• Key Mixing: The expanded half-block is XORed with the round key.
• Substitution: The 48-bit result is divided into eight 6-bit blocks, each of which is substituted with
a 4-bit value using a set of S-boxes (substitution boxes). The S-boxes provide non-linear mixing,
increasing the complexity of the encryption process.
• Permutation: The output of the S-boxes is permuted using another fixed table.
• XOR with the other half: The permuted half-block is XORed with the other 32-bit half-block.
• This process is repeated for a total of 16 rounds, with each round using a different round key
derived from the original key.
The final permutation is the inverse of the initial permutation, ensuring that the decryption
process is the reverse of the encryption process.
Secrete key cryptography
mode of operations:
In secret key cryptography, mode of operation are techniques used to encrypt
plaintext data using a block cipher. A block cipher operates on fixed-size blocks of
data, and produces cipher text of the same size. However, most data to be
encrypted is not a multiple of the block size, so mode of operation provide a way
to handle arbitrary-length plaintext.
Counter (CTR): CTR mode turns a block cipher into a stream cipher
by using a counter . The counter is incremented for each block of
plaintext, and the resulting counter value is encrypted and XORed
with the plaintext to produce the cipher text. This mode allows for
parallel encryption and decryption and does not require padding.
5. Man-in-the-Middle Attacks:
Description: An attacker intercepts and possibly alters the communication between two parties without their knowledge.
Prevention: Implementing secure key exchange protocols and using additional measures like digital signatures can
protect against man-in-the-middle attacks.
6 Side-Channel Attacks:
– Description: These attacks exploit information leaked during the encryption
process, such as power consumption, timing, or electromagnetic emissions.
– Prevention: Implementing countermeasures like constant-time algorithms,
using secure hardware, and regular security evaluations can help mitigate
side-channel attacks.
7 Replay Attacks:
– Description: An attacker captures and retransmits a valid data transmission to
gain unauthorized access.
– Prevention: Implementing mechanisms like timestamps or nonce values can
help detect and prevent replay attacks.
1. Linear Approximation:
Linear Cryptanalysis aims to find linear approximations of the behavior of a cryptographic algorithm.
A linear approximation is a relationship between plaintext, ciphertext, and key bits that holds with a certain
probability.
2. S-Boxes:
In many block ciphers, Substitution-Permutation Networks (SPNs) are used, where S-Boxes (Substitution Boxes) play
a crucial role. Linear Cryptanalysis often focuses on approximating the behavior of these S-Boxes.
5. Attack Process:
Linear Cryptanalysis involves collecting a set of plaintext-ciphertext pairs and deriving linear equations based on the
observed behavior. The attacker then tries to deduce key bits using these linear equations.
6. Statistical Testing:
– The success of a linear attack is measured by statistical testing. The attacker evaluates the
linear approximation against a set of plaintext-ciphertext pairs to determine how well it
correlates with the actual behavior of the cipher.
7. Data Complexity:
– Linear Cryptanalysis requires a sufficient number of plaintext-ciphertext pairs to generate
accurate linear approximations. The data complexity is the number of pairs needed for a
successful attack.
8. Key Recovery:
– Once a successful linear approximation is found and tested, the attacker may be able to
recover portions of the secret key. Further refinement and analysis might be required for a
complete key recovery.
• It's worth noting that the effectiveness of Linear Cryptanalysis depends on various
factors, including the structure of the cipher, the size of the linear approximation,
and the availability of a suitable number of plaintext-ciphertext pairs for analysis.
Modern block ciphers are designed to resist linear and other cryptanalytic attacks,
and thorough evaluation and testing are crucial for their security.