Lecture4 Cryptographyw
Lecture4 Cryptographyw
Key A Key B
• Encryption algorithms are standardized & published
• The key which is an input to the algorithm is secret
•Key is a string of numbers or characters
•If same key is used for encryption & decryption the algorithm is called
symmetric
• If different keys are used for encryption & decryption the algorithm is called
asymmetric
Dr. M. Muzaffar Hameed, Department of Computer Science, BZU Multan (PAKISTAN)
Dr. M. Muzaffar Hameed, Department of Computer Science, BZU Multan (PAKISTAN)
Encryption
Symmetric Algorithms
• Algorithms in which the key for encryption and
decryption are the same are Symmetric
• Example: Caesar Cipher
• Types:
1. Block Ciphers
– Encrypt data one block at a time (typically 64 bits, or 128 bits)
– Used for a single message
2. Stream Ciphers
– Encrypt data one bit or one byte at a time
– Used if data is a constant stream of information
ABCDEFGHIJKLMNOPQRSTUVWXYZ
DEFGHIJKLMNOPQRSTUVWXYZABC
Key (3)
Decryption
Cipher Text Plain Text
Cipher:
Message: Caesar Cipher Message:
Dwwdfn Dw Gdyq Algorithm Attack at Dawn
Key (3)
ABCDEFGH I JKLMNOPQRSTUVWXYZ
Message: Encrypted
Cipher: Message:
Bob, I tell you. Monoalphabetic Nkn, s gktc wky.
Alice Cipher mgsbc
Key
Substitution Cipher
Polyalphabetic Caesar Cipher
• Developed by Blaise de Vigenere
• Also called Vigenere cipher
• Uses a sequence of monoalpabetic ciphers in tandem
• e.g. C1, C2, C2, C1, C2
Message: Encrypted
Cipher: Message:
Bob, I tell you. Monoalphabetic Gnu, n etox dhz.
Alice Cipher tenvj
Key
Substitution Cipher
Using a key to shift alphabet
• Obtain a key for the algorithm and then shift the alphabets
• For instance if the key is word we will shift all the letters by four and remove the
letters w, o, r, & d from the encryption
• We have to ensure that the mapping is one-to-one
• no single letter in plain text can map to two different letters in cipher text
• no single letter in cipher text can map to two different letters in plain text
Message:
Encrypted
Cipher: Message:
Bob, I tell you.
??
Alice
WORD
Transposition Cipher
Columnar Transposition
In a Columnar Transposition cipher, the number of possible keys depends on the length of the
keyword used to perform the transposition.
The key in a Columnar Transposition cipher is typically a keyword that determines the order in
which columns are written out. The length of the keyword determines the number of columns
used in the transposition. For example, if the keyword is "KEY", then there are 3 columns used in
the transposition.
The number of possible keys can be calculated based on the permutations of the unique letters in
the keyword. For example, if the keyword has 3 unique letters, there are 3! (3 factorial)
permutations of those letters. If some letters are repeated, then you would divide by the factorial
of the number of times each letter is repeated to account for duplicate permutations.
For instance, if the keyword is "SECRET", there are 3 unique letters (S, E, C), and the letter E is
repeated twice. So, the number of permutations would be 6! / (2! * 2!) = 720 / 4 = 180.
Therefore, for a Columnar Transposition cipher with a keyword of length n and m unique letters,
the number of possible keys is n! / (p₁! * p₂! * ... * pₘ!), where p₁, p₂, ..., pₘ are the factorials of the
number of times each unique letter is repeated in the keyword.
Transposition Cipher
Columnar Transposition
• This involves rearrangement of characters on the plain text into columns
• The following example shows how letters are transformed
• If the letters are not exact multiples of the transposition size there may be a
few short letters in the last column which can be padded with an infrequent
letter such as x or z