S 4 - Cryptography and Encryption Algorithms
S 4 - Cryptography and Encryption Algorithms
Encryption Algorithms
B B Chakrabarti
Professor of Finance
Cryptography - Definition
• Cryptography is a method of protecting information and
communications through the use of codes so that only
those for whom the information is intended can read and
process it. The pre-fix "crypt" means "hidden" or "vault"
and the suffix "graphy" stands for "writing.“
• In computer science, cryptography refers to secure
information and communication techniques derived from
mathematical concepts and a set of rule-based calculations
called algorithms to transform messages in ways that are
hard to decipher.
• These deterministic algorithms are used for cryptographic
key generation and digital signing and verification to
protect data privacy, web browsing on the internet and
confidential communications such as credit card
transactions and email.
Cryptography - Definition
• In cryptography, we start with the unencrypted data,
referred to as plaintext. Plaintext is encrypted into
ciphertext, which will in turn be decrypted back into
usable plaintext. The encryption and decryption is
based upon the type of cryptography scheme being
employed and some form of key.
• This process is can be written as:
C = Ek(P)
P = Dk(C)
where P = plaintext, C = ciphertext, E =encryption
method, D = decryption method, and k = key.
Cryptography - Definition
• Two communicating parties will be referred to as
Alice and Bob; this is the common nomenclature in
the crypto field and literature to make it easier to
identify the communicating parties.
• If there is a third and fourth party to the
communication, they will be referred to as Carol and
Dave, respectively.
• A malicious party is referred to as Mallory, an
eavesdropper as Eve, and a trusted third party as
Trent.
Cryptography - Functions
• There are five primary functions of cryptography:
• Privacy/confidentiality: Ensuring that no one can read
the message except the intended receiver.
• Authentication: The process of proving one's identity.
• Integrity: Assuring the receiver that the received
message has not been altered in any way from the
original.
• Non-repudiation: A mechanism to prove that the sender
really sent this message.
• Key exchange: The method by which crypto keys are
shared between sender and receiver.
Cryptographic Algorithms
• The three types of algorithms are:
• Secret Key Cryptography (SKC): Uses a single key for
both encryption and decryption; also
called symmetric encryption. Primarily used for
privacy and confidentiality.
• Public Key Cryptography (PKC): Uses one key for
encryption and another for decryption; also
called asymmetric encryption. Primarily used for
authentication, non-repudiation, and key exchange.
• Hash Functions: Uses a mathematical transformation
to irreversibly "encrypt" information, providing a
digital fingerprint. Primarily used for message
integrity.
Cryptographic Algorithms
Secret Key Cryptography
• Secret key cryptography methods employ a single key for both
encryption and decryption.
• The sender uses the key to encrypt the plaintext and sends
the ciphertext to the receiver.
• The receiver applies the same key to decrypt the message and
recover the plaintext.
• Because a single key is used for both functions, secret key
cryptography is also called symmetric encryption.
• With this form of cryptography, it is obvious that the key must
be known to both the sender and the receiver; that, in fact, is
the secret. The biggest difficulty with this approach, of course,
is the distribution of the key.
Public Key Cryptography
• PKC employs two keys that are mathematically related
although knowledge of one key does not allow someone to
easily determine the other key. One key is used to encrypt the
plaintext and the other key is used to decrypt the ciphertext.
• Because a pair of keys are required, this approach is also
called asymmetric cryptography.
• In PKC, one of the keys is designated the public key and may
be advertised as widely as the owner wants. The other key is
designated the private key and is never revealed to another
party. It is straight-forward to send messages under this
scheme.
• Suppose Alice wants to send Bob a message. Alice encrypts
some information using Bob's public key; Bob decrypts the
ciphertext using his private key.
Public Key Cryptography
PKC – Method RSA
• Some Math:
a) Mod operator
13/5 = 2 remainder 3
13 mod 5 = 3
b) Prime number – A prime is a number that can
only be divided without a reminder by itself and 1.
c) Euler’s Totient – It is the count of no. of elements
in a prime no. If p is a prime no., Totient φ (p) = p-1
RSA – Key Generation
1) Two large prime nos. p and q are needed.
2) Calculate the modulus, n = p x q
3) Totient of n = φ (n) = (p-1)*(q-1)
4) Public key (expressed as e) – A prime no. is
calculated from the range (3, φ (n)) that has a
gcd of 1 with φ (n)
5) Private key (expressed as d) – It is the
multiplicative inverse of the public key with
respect to mod φ (n)
RSA – Simple Example
Suppose the plaintext message is 9.
We choose p = 11 and q = 13
Then n = 11*13 = 143
φ (n) = (11-1)*(13-1) = 120
Public key e is a prime no. less than φ (n) and has a gcd (greatest
common divisor) of 1 with φ (n). Let us choose e = 7
Private key, d is a no. such that e*d = 1 (mod (φ (n))). Using Extended
Euclidean Algorithm, we can find d = 103. e*d then = 721 =
1(mod120)
Encrypted message, c is 48 since
me mod n = 97 mod 143 = 48
Decrypted message is m again since
cd mod n = 48103 mod143 = 9 = m
RSA – Real World Example
1) Plaintext – “Attack at dawn”
2) We convert this message into a numeric format. First the string
is converted to a bit array and then to a large number using
ASCII (American Standard Code for Information Interchange)
characters. The numeric text becomes
1976620216402300889624482718775150.
3) Key generation – We pick two large prime nos. p and q using
Rabin-Miller primality tests. These nos. must be random and not
too close to each other.
4) We generate p =
1213107243921127189732367153161244042847242763370141
0925634549312301964373042085619324197365322416866541
017057361365214171711713797974299334871062829803541
RSA – Real World Example
5) And q =
1202752425547874888595622079373451212873338780368207543365389
9983955179850988797899869146900809131611153346817050832096022
160146366346391812470987105415233
6) Hence, n = p * q =
1459067680075833232301869393490706352924018723753571643995818
7101987343879900535893836957140267014980212181808629246742282
8157022922076746906543401224889672472407926969987100581290103
1993178587536637108623576565105078837142971156373427889114635
3510271203276516651841172685983798867211183720508552634661874
0053
7) φ (n) = (p-1)*(q-1) =
1459067680075833232301869393490706352924018723753571643995818
7101987343879900535893836957140267014980212181808629246742282
8157022922076746906543401224889648313811232279966317301397777
8523653015478482734788712972220585874571528916064592697181192
6897116355507080264399952954964411681194751651393818429668352
1280
RSA – Real World Example
8) e – The public key – Let us choose 65537. It has a gcd of 1
with φ (n)
9) d – the private key is the multiplicative inverse of the public
key with respect to mod φ (n). We use extended Euclidean
algorithm to find d.
d=
8948942500927444436822854592177309391966958606588425
7445497854456487674839629818390934941973262879616797
9706089172836798754993315741611138540888132754881105
8824719307758252727843790650401568062342355006724004
2466665654232383502922215493623289472138866445818789
127946123407807725702626644091036502372545139713
RSA – Real World Example
• Now, Plaintext = Attack at dawn
• Numeric text, m = 1976620216402300889624482718775150
• Encrypted message, c = me mod n =
35052111338673026690212423937053328511880760811579
98162064280234668581062310985023594304908097338624
11137840407947041939782153784997654130836464387847
40952306932534945195080183861574225226218879827232
45391282059688644037753608246568175007441745915148
54074458625110234722355608230534977915189288202722
57787786
• Decrypted message = cd mod n =
1976620216402300889624482718775150
= m = Attack at dawn
Applications of PKC
• The most obvious application of a public key encryption system is in
encrypting communication to provide confidentiality – a message that a
sender encrypts using the recipient's public key can be decrypted only by
the recipient's paired private key.
• Another application in public key cryptography is the digital signature.
Digital signature schemes can be used for sender authentication.
• Non-repudiation system use digital signatures to ensure that one party
cannot successfully dispute its authorship of a document or
communication.
• Further applications include: digital cash, password-authenticated key
agreement, time-stamping services, non-repudiation protocols, etc.
• Because asymmetric key algorithms are nearly always much more
computationally intensive than symmetric ones, in many cases it is
common to exchange a key using a key-exchange algorithm, then transmit
data using that key and a symmetric key algorithm. PGP, SSH, and
the SSL/TLS family of schemes use this procedure, and are thus
called hybrid cryptosystems.
PKC - Algorithms