cn-Syllabus_Unit_1-_FOC
cn-Syllabus_Unit_1-_FOC
Unit 01
Introduction of cryptography, Symmetric-key Encryption, Historical Ciphers, Computational
Security, Semantic Security and Pseudorandom Generators (PRGs), Perfect secrecy. One-time-
pad encryption. Characterizations of perfect secrecy, Limitations of perfect secrecy.
Unit 02
CPA-Secure Ciphers from PRF, Modes of Operations of Block Ciphers, DES, AES and Message
Authentication Codes (MAC), Information-theoretic Secure MAC, Cryptographic Hash
Functions.
Unit 03
Ideal-Cipher Model, Davies-Meyer construction and Merkle - Damgård Paradigm, Birthday
Attacks on Cryptographic Hash Functions, Applications of Hash Functions, Random Oracle
Model and Authenticated Encryption. Generic Constructions of Authenticated Encryption
Schemes, Key-exchange Problem, One-way Trapdoor Functions and Cyclic Groups.
Unit 04
Discrete-Logarithm Problem, Computational Diffie-Hellman Problem, Decisional, Diffie-
Hellman Problem, Elliptic-Curve Based Cryptography and Public-Key Encryption.
Unit 05
CCA -secure Public-key Hybrid Ciphers Based on Diffie-Hellman Problems and RSA-
assumption, Digital Signatures, Overview of TLS/SSL, Number Theory, Interactive Protocols.
Applications of Cryptography:
Advantages
1. Access Control: Cryptography can be used for access control to ensure that only
parties with the proper permissions have access to a resource. Only those with the
correct decryption key can access the resource thanks to encryption.
2. Secure Communication: For secure online communication, cryptography is
crucial. It offers secure mechanisms for transmitting private information like
passwords, bank account numbers, and other sensitive data over the internet.
3. Protection against attacks: Cryptography aids in the defence against various types
of assaults, including replay and man-in-the-middle attacks. It offers strategies for
spotting and stopping these assaults.
4. Compliance with legal requirements: Cryptography can assist firms in meeting a
variety of legal requirements, including data protection and privacy legislation.
Symmetric Key Encryption: Encryption is a process to change the form of any message in
order to protect it from reading by anyone. In Symmetric-key encryption the message is
encrypted by using a key and the same key is used to decrypt the message which makes it easy
to use but less secure. It also requires a safe method to transfer the key from one party to
another.
Asymmetric Key Encryption: Asymmetric Key Encryption is based on public and private key
encryption techniques. It uses two different key to encrypt and decrypt the message. It is more
secure than the symmetric key encryption technique but is much slower.
The size of cipher text is the same or smaller The size of cipher text is the same or larger
than the original plain text. than the original plain text.
The length of key used is 128 or 256 bits The length of key used is 2048 or higher
In this, the same key (secret key) and In public-key cryptography, two keys are
algorithm are used to encrypt and decrypt used, one key is used for encryption, and
2. the message. the other is used for decryption.
In private key cryptography, the key is In public-key cryptography, one of the two
3. kept a secret. keys is kept a secret.
The private key is Symmetrical because The public key is Asymmetrical because
there is only one key that is called a secret there are two types of keys: private and
4. key. public keys.
In this cryptography, the sender and In this cryptography, the sender and
5. receiver need to share the same key. receiver do not need to share the same key.
8. It is used for large amounts of text. It is used for only short messages.
There is the possibility of losing the key There is less possibility of key loss, as the
9. that renders the systems void. key is held publicly.
The private key is used in algorithms such The public key is used in algorithms such
12. as AES 128, AES 192 and AES 256. as RSA, DSA, etc.
13. The private key is kept secret. The public key is widely distributed.
It is used to protect disk drives and other It is used to secure web sessions and
14. data storage devices. emails.
The recipient’s private key decrypts the The recipient’s public key encrypts the
15. message. message.
Like most technologies, encryption has evolved throughout the years from simple origins. While
modern encryption relies on complex computational operations, older encryption ciphers were
rudimentary and easy to break. Regardless of each cipher’s strength, all encryption methods
share a common goal, to encode a readable “plaintext” message in a way that prevents
unauthorized individuals from reading it. Let’s explore the history of encryption and some
historical ciphers that were used to hide messages from prying eyes.
Substitution Ciphers
The Caesar cipher, also called a Caesar shift, gets its name from Julius Caesar, who occasionally
used this encoding method in his own private messages. As one of the most basic encryption
techniques, the Caesar cipher works by replacing each letter in the original plaintext message
with a different letter based off a fixed shift of the alphabet.
For example, let’s say we want to encode a secret message using a Caesar shift of 7 to the right.
First, we create our substitution table by printing the alphabet followed by the alphabet shifted 7
places to the right.
Original: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Shifted: TUVWXYZABCDEFGHIJKLMNOPQRS
Next, we take each letter of our plaintext message and replace it with its corresponding letter in
the shifted alphabet.
Plaintext: THISISASECRETMESSAGEBURNAFTERREADING
Ciphertext: MABLBLTLXVKXMFXLLTZXUNKGTYMXKKXTWBGZ
To revert the encoded message back into its readable plaintext form, the recipient must re-create
the substitution table using the appropriate shift and then substitute each encoded character with
its original character, according to the shift.
One take on the Caesar cipher that has reached internet stardom is ROT13, which equates to a
rotation (or shift) of 13 places. Because the basic English alphabet is 26 characters long, ROT13
is its own inverse, allowing the same algorithm to both encode and decode messages.
A Vigenère cipher uses a table consisting of different Caesar shifts in sequence and a key to
encode a message across several rows of the table. By using different Caesar shifts for different
characters in the message, the Vigenère cipher makes decoding the ciphertext using frequency
analysis much more difficult.
Plaintext: THISISASECRETMESSAGEBURNAFTERREADING
KEY: FIREWALLFIREWALLFIREWALLFIREWALLFIRE
To generate the encoded ciphertext, we match the plaintext character to a column and the
corresponding key letter to a row in the Vigenère table. For example, the first letter in our
plaintext is “T” and its corresponding key is “F”. Row “F”, column “T” would give us the
ciphertext character “Y”. This process is repeated sequentially for the entirety of the plaintext.
Plaintext: THISISASECRETMESSAGEBURNAFTERREADING
KEY: FIREWALLFIREWALLFIREWALLFIREWALLFIRE
Ciphertext: YPZWESLDJKIIPMPDXIXIXUCYFNKINRPLIQEK
To decode each character in the message, the recipient again selects the row indicated by the key
character, locates the ciphertext character within the row, and notes the column. For example, to
decode the last character in the message above, you would go to row “E” of the table and locate
character “K” which maps to column “G”, the plaintext character.
Playfair Cipher
The Playfair cipher is a diagraph substitution cipher. Instead of encoding a message by replacing
individual characters, it replaces them in pairs. To encode a message, the Playfair cipher uses a
keyword to generate a 5 by 5 encoding table and then follows 4 rules to encode diagrams (pairs
of characters) using the table.
To create a Playfair cipher table, you use a keyword to fill spaces in a 5 by 5 table top to bottom,
left to right. Any duplicate letters from the keyword are omitted when filling out the table.
Furthermore, the letters I and J are placed in the same space to shrink the 26-character alphabet
into a 25-character table. The remaining spaces in the table are filled with the rest of the letters of
the alphabet in order.
For example, let’s assume our keyword is “Picture Frame”. To create a Playfair cipher table, we
would begin by writing “Picture Frame” in a 5 by 5 table, omitting repeated characters. Note in
the example table below, the “R” and “E” from “Frame” are skipped because they were already
placed in the table. After writing out the keyword, the rest of the spaces in the table are filled out
with the remaining letters of the alphabet. In our example, “J” is skipped when filling in the rest
of the table because it shares a space with “I” from the keyword.
1. If both letters in the diagram are the same, add an X after the first letter to split
them into a new diagram and continue encoding the message.
2. If they appear in the same row of the table, shift the characters one position to the
right, wrapping around the table if needed.
3. If they appear in the same column, shift the characters down one position,
wrapping around the table if needed.
4. If they form the corners of a rectangle, replace them with the characters forming
the opposing corners of the rectangle, left to right.
These rules are much easier to understand with an example. To encode the message “KI LL TH
ES PY” using the table we created earlier, we begin by look at the first diagram, “KI”, and map it
to the table.
The letters “K” and “I” form opposing corners of a rectangle, which means rule 4 applies. We
replace “K” with the opposite corner in its same row, in this case “D”. “I” meanwhile is replaced
with “U”.
The letters “L” and “X” also form the corners of a rectangle, which means we replace them with
the opposing corners to form the encoded diagram “OV.”
Because we split the previous diagram, our third diagram is now “LT.” “L” and “T” form
opposing corners of another rectangle, which means our encoded diagram is “QP.”
Continuing through the message, “HE” forms yet another rectangle in our table and gives us
“DA” for the encoded diagram. The next diagram “SP” forms a rectangle giving us “LU” as the
encoded diagram.
Finally, because our secret message only has one character left, “Y”, we add “X” to form the
diagram “YX”. The characters “Y” and “X” appear in the same row of our table which means
rule 2 applies.
Transposition Ciphers
Rail Fence Cipher
The rail fence cipher is a simple transposition cipher where plaintext characters are re-arranged
instead of replaced to encode a message. The rail fence cipher encodes a message by writing it
down and up diagonally over successive “rails”, or rows, in an imaginary fence. For example, the
secret message “THIS IS A SECRET MESSAGE” encoded over 4 rails would look like this.
T.....A.....T.....G.
.H...S.S...E.M...A.E
..I.I...E.R...E.S...
...S.....C.....S....
We then create the ciphertext by reading off characters left to right, top to bottom. For our
example message, the cipher text becomes:
TATGHSSEMAEIIERESSCS
Decoding a message only requires knowing the number of “rails” used to encode the message
and solving a simple math equation to determine the spacing between letters. To decode the
ciphertext, you first determine the size of the “cycle”, that is the number of characters in one full
movement down and up the “fence”. For a ciphertext created using 4 “rails”, the cycle is 6
After calculating the size of the cycle, divide the number of characters in the ciphertext by the
size of the cycle to find the number of cycles used to encode the message. Our ciphertext for
example is 20 characters long, which gives us 3 full cycles and a partial cycle of 2 characters
when divided by a cycle size of 6. Finally, we use this information to write the ciphertext back
out on the “fence” for decoding.
In our example, we calculated 3 full cycles and one partial cycle of 2 characters, which means
the top row of the fence should consist of the first 4 characters of our ciphertext (3 cycles + the
start of the partial cycle.)
T.....A.....T.....G.
The second row uses the next 7 characters of our ciphertext (2x the number of cycles + the
second extra character from the partial cycle.)\
T.....A.....T.....G.
.H...S.S...E.M...A.E
The third row uses the next 6 characters, that is 2x the number of cycles.
T.....A.....T.....G.
.H...S.S...E.M...A.E
. . I . I. . . . E R . . . E . S . . .
And the final row uses the last three characters, one for each full cycle.
T.....A.....T.....G.
.H...S.S...E.M...A.E
..I.I...E.R...E.S...
...S.....C.....S....
Finally you can read the decoded message by following the text pattern down and up the “fence”.
Route Cipher
The route cipher is another very simple transposition cipher. To use the route cipher, you write
out your plaintext message into a grid of arbitrary dimensions. For example, “THIS IS A
SECRET MESSAGE BURN AFTER READING” might be written out:
TIETSBARD
HSCMAUFRI
IAREGRTEN
SSESENEAG
GAENESESSIHTIETSBARDINETRGERASCMAUFR
To decode the ciphertext, the recipient must know the pattern used and the size of the grid. They
would then simply follow the pattern in reverse to form a grid of the given size.
Book Cipher
The book cipher is an encryption method often used in popular culture. With a book cipher, both
the sender and recipient of a secret message must have the same copy of a book, usually down to
the same edition. The sender then encodes the secret message word-by-word by replacing the
plaintext word with coordinates mapping to the location of the same word within the chosen
book. For example, if the word “Kill” appeared in the book on page 39, paragraph 7, word 12,
the ciphertext coordinates would be {39:7:12}. To decode the word, the recipient would find the
word within their copy of the book in the notated position.
To solve the problem of encoding a message that includes words not contained in the book, the
sender could instead encode it character-by-character. The ciphertext coordinates could either
point to individual letters in the book or to words where the resulting plaintext character is the
first character of the word.
One-Time Pad
A one-time pad is an encryption technique that cannot be solved by brute-force (trying every
possible combination of key in hopes of outputting the original plaintext message). Encrypting a
message using a one-time pad requires a single-use pre-shared key of the same size or larger than
the plaintext message being encoded. Both the sender and the recipient of the message must
know the key but it must also be kept secret from everyone else.
So long as the same “pad” is never used twice, the ciphertext remains secure. Messages
encrypted using a one-time pad are resistant to cryptanalysis because it is possible to decode the
ciphertext into any plaintext message with the same number of characters as the original
plaintext message by using different keys. Specifically, there is no information in the ciphertext
that allows differentiating between multiple potential plaintext decodings of the same ciphertext.
Encoding a message with a one-time pad requires using modular addition, which is best
explained with an example. Let’s say we want to encode the plaintext message “KILL THE
SPY.” We must first select a one-time pad to use. Historically, one-time pads were generated as
a stack of pages. Both parties then agreed on which specific page to use in advanced. For this
example, we assume our agreed-upon one-time pad is:
HQWORJIHKSGSICOSFSSB
PCWCHGXYOUMWEOYYWUKY
While modular addition sounds complicated, it is actually very simple. First, add the two
numbers together like normal. Then, if the resulting number is equal to or larger than 26 (our
mod value), subtract 26 from it. The resulting number is the numeric value of the ciphertext
character.
K I L L T H E S P Y message
10(K) 8(I) 11(L) 11(L) 19(T) 7(H) 4(E) 18(S) 15(P) 24(Y) message
+ 7(H) 16(Q) 22(W) 14(O) 17(R) 9(J) 8(I) 7(H) 10(K) 18(S) key
= 17 24 33 25 36 16 12 25 25 42 message + key
= 17(R) 24(Y) 7(H) 25(Z) 10(K) 16(Q) 12(M) 25(Z) 25(Z) 16(Q) (message + key) mod 26
R Y H Z K Q M Z Z Q ciphertext
In the above example, our plaintext message “KILL THE SPY” becomes “RYHZKQMZZQ”
using the one-time pad.
To decode the message, the same process is used, just in reverse. We subtract the key from the
ciphertext and if the result is negative we add 26.
R Y H Z K Q M Z Z Q ciphertext
17(R) 24(Y) 7(H) 25(Z) 10(K) 16(Q) 12(M) 25(Z) 25(Z) 16(Q) ciphertext
- 7(H) 16(Q) 22(W) 14(O) 17(R) 9(J) 8(I) 7(H) 10(K) 18(S) key
= 10 8 -15 11 -7 7 4 18 15 -2 ciphertext - key
= 10(K) 8(I) 11(L) 11(L) 19(T) 7(H) 4(E) 18(S) 15(P) 24(Y) ciphertext - key (mod 26)
K I L L T H E S P Y message
Computational Security
Conditionally or computationally secure cryptography uses a shared secret key of limited length
to provide security against an opponent with limited computational resources by making it
computationally infeasible extract the key or message.
Some ciphers are easy to crack and others are very difficult. In practice, perfect security is
impossible to achieve. Most ciphers used today rely on computational security. This means that
they rely on the fact that there is no computer system powerful enough to crack the cipher in a
reasonable amount of time.
Answer:
Even if the key comprises only letters, there are 26 options for each character of the plain text
message. This means that the message 'HELLO' would have 26, to the power 5
,265 (11,881,376) possible representations, including all possible five-letter words. Thus, even if
you used a computer to generate a list of all the possibilities, you could not determine the correct
plain text.
However, there are some rules that must be followed to achieve perfect security:
The key must be the same length as (or longer than) the plain text
The characters in the key must be truly random
The key must be used once, and only once
There must be only two copies of the key (held by the sender and recipient) and the key
must be secret to these parties
The key must be destroyed after use
Most modern cryptography schemes rely not on perfect security, but on computational security.
A reasonable time depends on the task in hand. If you intercepted the encrypted login details for
someone's bank account, spending a few days to decrypt it would probably be fine. However,
spending years to decrypt it is unlikley to be useful; after a few years the account may have been
closed or the password may have been changed. If cracking the cipher text takes hundreds or
thousands of years, the information will definitely not be useful.
Semantic Security
In cryptography, a semantically secure cryptosystem is one where only negligible information
about the plaintext can be feasibly extracted from the ciphertext.
Pseudo Random Number Generator
Pseudo Random Number Generator(PRNG) refers to an algorithm that uses mathematical
formulas to produce sequences of random numbers. PRNGs generate a sequence of numbers
approximating the properties of random numbers. A PRNG starts from an arbitrary starting
state using a seed state. Many numbers are generated in a short time and can also be
reproduced later, if the starting point in the sequence is known. Hence, the numbers
are deterministic and efficient.
Characteristics of PRNG
Efficient: PRNG can produce many numbers in a short time and is advantageous
for applications that need many numbers
Deterministic: A given sequence of numbers can be reproduced at a later date if the
starting point in the sequence is known. Determinism is handy if you need to replay
the same sequence of numbers again at a later stage.
Periodic: PRNGs are periodic, which means that the sequence will eventually
repeat itself. While periodicity is hardly ever a desirable characteristic, modern
PRNGs have a period that is so long that it can be ignored for most practical
purposes.
Applications of PRNG
PRNGs are suitable for applications where many random numbers are required and where it is
useful that the same sequence can be replayed easily. Popular examples of such applications
are simulation and modeling applications. PRNGs are not suitable for applications where it
is important that the numbers are really unpredictable, such as data encryption and gambling.
#include<bits/stdc++.h>
using namespace std;
int main()
{
Output 1:
3 7 0 9 8
Output 2:
7 6 8 1 4
perfect secrecy
The definition of perfect secrecy is based on statistics and probabilities. A ciphertext maintains
perfect secrecy if the attacker's knowledge of the contents of the message is the same both before
and after the adversary inspects the ciphertext, attacking it with unlimited resources.
Perfect Secrecy (or information-theoretic secure) means that the ciphertext conveys no
information about the content of the plaintext. In effect this means that, no matter how much
ciphertext you have, it does not convey anything about what the plaintext and key were. It can be
proved that any such scheme must use at least as much key material as there is plaintext to
encrypt. In terms of probabilities, it means that the probability distribution of the possible
plaintexts is independent of the ciphertext.
Limitations
1) The key must be as long as the message.
2) The key can be used only once to encrypt a single message securely and hence its name
(OTP). Things start getting really messy when one reuses a one-time pad. As a matter of fact, US
and UK exploited this drawback to decrypt Russian plaintext in the Venona Project.
We show that one of the aforementioned limitations of the one-time pad encryption scheme is
inherent. We prove that any prefectly-secret encryption scheme must have a key space that is at
least as large as the message space.
What is the characterization of perfect secrecy?
Perfect secrecy of the cipher
The Vernam cipher has the perfect secret property if: (i) the key exchanged is as long as the
message, (ii) each key is used only once and is uncorrelated to the new one, and (iii) the key is
known only by the users.