You are on page 1of 4

2/24/2019 Understanding Cryptography by Christof Paar and Jan Pelzl - Chapter 2 Solutions - Ex2.

1 | Tom Busby

Home Blog Projects About

Understanding Cryptography by Christof Paar and


Jan Pelzl - Chapter 2 Solutions - Ex2.1
SUNDAY. 17 DECEMBER 2017 - 3 MINS

CRYPTOGRAPHY UNDERSTANDING-CRYPTOGRAPHY EVEN-NUMBERED-SOLUTIONS

Return to index
Exercise 2.1
Exercise 2.2
Exercise 2.3
Exercise 2.4
Exercise 2.5
Exercise 2.6
Exercise 2.7
Exercise 2.8
Exercise 2.9
Exercise 2.10
Exercise 2.11
Exercise 2.12

Exercise 2.1
The stream cipher described in Definition 2.1.1 can easily be generalized to work in alphabets
other than the binary one. For manual encryption, an especially useful one is a stream cipher
that operates on letters.

1. Develop a scheme which operates with the letters A, B,…, Z, represented by the numbers 0,1,
…,25. What does the key (stream) look like? What are the encryption and decryption
functions?
2. Decrypt the cipher text “bsaspp kkuosp” which was encrypted using the key “rsidpy dkawoa”.
3. How was the young man murdered?

https://tom.busby.ninja/understanding-cryptography/ex2-1/ 1/4
2/24/2019 Understanding Cryptography by Christof Paar and Jan Pelzl - Chapter 2 Solutions - Ex2.1 | Tom Busby

Solution

This solution is verified as correct by the official Solutions for Odd-Numbered Questions
manual.

1. Assuming the keystream is a stream of random bits in Z26 , we can define a stream cipher
on the Latin Alphabet as follows (where A ↔ 0, B ↔ 1, C ↔ 2 etc):

yi = xi + ki mod 26

xi = yi − ki mod 26

2. There is a mistake in the book, the key should be “rsidpy dkawoy”. If you use this key to
decrypt the ciphertext, we get the following message:

KASPAR HAUSER

3. Kaspar Hauser was murdered by knife wound.

I wrote a python script which can perform encryption and decryption with this system:

def letter_to_number(c):
return ord(c.lower()) - ord('a')

def number_to_letter(n):
return chr(n % 26 + ord('a'))

def encrypt_letter(key, plaintext):


if plaintext == " ": return plaintext
key = letter_to_number(key)
plaintext = letter_to_number(plaintext)
return number_to_letter((plaintext + key) % 26)

def decrypt_letter(key, ciphertext):


if ciphertext == " ": return ciphertext
key = letter_to_number(key)
ciphertext = letter_to_number(ciphertext)
return number_to_letter((ciphertext - key) % 26)

def encrypt(key, plaintext):


return "".join(encrypt_letter(k, p) for (k, p) in zip(key, plaintext))

def decrypt(key, ciphertext):


return "".join(decrypt_letter(k, c) for (k, c) in zip(key, ciphertext))

https://tom.busby.ninja/understanding-cryptography/ex2-1/ 2/4
2/24/2019 Understanding Cryptography by Christof Paar and Jan Pelzl - Chapter 2 Solutions - Ex2.1 | Tom Busby

def print_ciphertext_and_key(key, ciphertext):


print "\n===="
print "Key:"
print "====\n"
print key
print "\n==========="
print "Ciphertext:"
print "===========\n"
print ciphertext

def print_plaintext(plaintext):
print "\n=========="
print "Plaintext:"
print "==========\n"
print plaintext, "\n"

if __name__ == "__main__":
ciphertext = "bsaspp kkuosp"
key = "rsidpy dkawoy" # mistake in the key in the book, should end with y not a
print_ciphertext_and_key(key, ciphertext)
plaintext = decrypt(key, ciphertext)
print_plaintext(plaintext)
print "Q2.1.3: Kaspar Hauser was murdered via a stab wound\n"

Previous Exercise Next Exercise

Thomas Busby
Tweet Share
I write about computing stuff

https://tom.busby.ninja/understanding-cryptography/ex2-1/ 3/4
2/24/2019 Understanding Cryptography by Christof Paar and Jan Pelzl - Chapter 2 Solutions - Ex2.1 | Tom Busby

0 Comments Tom Busby's Blog 


1 Login

 Recommend t Tweet f Share Sort by Best

Start the discussion…

LOG IN WITH
OR SIGN UP WITH DISQUS ?

Name

Be the first to comment.

✉ Subscribe d Add Disqus to your siteAdd DisqusAdd 🔒 Disqus' Privacy PolicyPrivacy PolicyPrivacy

Tom Busby © 2018


Indigo theme by Kopplin

https://tom.busby.ninja/understanding-cryptography/ex2-1/ 4/4

You might also like