Cryptanalysis: Key Concepts and Techniques

Introduction to Computer Science Topic 2
 (Part 3)
Contents for Topic 2 (part 3)
ใƒป
Cryptanalysis
Goals of Topic 2
To learn what programming is.
To learn some key programming techniques.
ใƒป
Function (or subroutine)
โœ”
Part 3.2.  Cryptanalysis
What is cryptography?
 
โ€ป Cryptography is not only for communication; for example,
    we may use it when storing data.
Basic flow of cryptographic communication
Let's define the basic
cryptographic tools as functions.
encryption function
 
enc
 (
encryption key
 
๐‘˜
, plaintext
 
๐‘š
)
                 
=
 
ciphertext
 for 
๐‘š
 
(obtained by shifting 
๐‘˜
 
letters).
decryption function
 
dec
 
(
encryption key 
๐‘˜
,
 
ciphertext 
๐‘
)
                  =
 
plaintext for 
๐‘
 
(obtained by
 
reverse
 shifting 
๐‘˜
 
letters).
 
Caesar cipher
Part 3.2.  Cryptanalysis
Part 3.2.  Cryptanalysis
What is cryptanalysis?
Basic flow of cryptographic communication
Let's define the basic
cryptographic tools as functions.
encryption function
Caesar cipher
Part 3.2.  Cryptanalysis
decryption function
analysis function
 
analysis
 
(ciphertext
 
๐‘
)
 
=
 
plaintext for 
๐‘
.
enc
 (
encryption key
 
๐‘˜
, plaintext
 
๐‘š
)
                 
=
 
ciphertext
 for 
๐‘š
 
(obtained by shifting 
๐‘˜
 
letters).
dec
 
(
encryption key 
๐‘˜
,
 
ciphertext 
๐‘
)
                  =
 
plaintext for 
๐‘
 
(obtained by
 
reverse
 shifting 
๐‘˜
 
letters).
Let's define the basic
cryptographic tools as functions.
encryption function
Caesar cipher
Part 3.2.  Cryptanalysis
decryption function
analysis function
analysis
 
(ciphertext
 
๐‘
)
 
=
 
plaintext for 
๐‘
.
Example
enc
 (
encryption key
 
๐‘˜
, plaintext
 
๐‘š
)
                 
=
 
ciphertext
 for 
๐‘š
 
(obtained by shifting 
๐‘˜
 
letters).
dec
 
(
encryption key 
๐‘˜
,
 
ciphertext 
๐‘
)
                  =
 
plaintext for 
๐‘
 
(obtained by
 
reverse
 shifting 
๐‘˜
 
letters).
Part 3.2.  Cryptanalysis
How to implement?
def enc(k, m)
   
   
return c
end
#### program body#####
k = 7
plaintext = gets.chomp
ciphertext = enc(k, plaintext)
puts(ciphertext)
encrypt.rb
Part 3.2.  Cryptanalysis
def enc(k, m)
   
   return c
end
#### program body#####
k = 7
plaintext = gets.chomp
ciphertext = enc(k, plaintext)
puts(ciphertext)
encrypt.rb
def
 
dec
(k, 
c
)
   
   
return
 
m
end
#### program body#####
k = 7
ciphertext
 = gets.chomp
plaintext
 = dec(k, 
ciphertext
)
puts(
plaintext
)
 
Converting to a plaintext m
decrypt.rb
How to implement?
Part 3.2.  Cryptanalysis
def enc(k, m)
   
   
return c
end
#### program body#####
k = 7
plaintext = gets.chomp
ciphertext = enc(k, plaintext)
puts(ciphertext)
encrypt.rb
def 
dec
(k, 
c
)
   
   return 
m
end
#### program body#####
k = 7
ciphertext
 = gets.chomp
plaintext
 = dec(k, 
ciphertext
)
puts(
plaintext
)
Converting to a plaintext m
decrypt.rb
How to implement?
Letโ€™s consider 
!!
Part 3.2.  Cryptanalysis
How to implement?
Complete the definition of subroutine โ€œdecโ€ for decryption.
def enc(k, m)
  
# prepare
   
code_a = 97
   leng = m.length
   
# compute ciphertext
   a = m.unpack("C*")
   b = Array.new(leng)
   for  i in 0..(leng-1)
      dist = a[i] - code_a
      if 0 <= dist && dist <= 25
         
b[i] = code_a + ((dist + k)%26))
      else
         b[i] = a[i]
      end
   end  
   c = b.pack(โ€œC*โ€)
   return c
end
 
hint:
subroutine enc
Letโ€™s consider 
!!
Part 3.2.  Cryptanalysis
How to implement?
Complete the definition of subroutine โ€œdecโ€ for decryption.
def
 
dec
(k
, 
c
)
  
# prepare
   
code_a = 97
   leng = 
c
.length
   
# compute ciphertext
   a = 
c
.unpack("C*")
   b = Array.new(leng)
   for  i in 0..(leng-1)
      dist = a[i] - code_a
      if 0 <= dist && dist <= 25
         
b[i] =
      else
         b[i] = a[i]
      end
   end  
   
m
 = b.pack(โ€œC*โ€)
   
return
 
m
end
b[i] = code_a + ((dist + k)%26))
ๅˆฅ็”ป้ขใฎไฝฟใ„ๆ–นใฎไพ‹๏ผˆใใฎ๏ผ’๏ผ‰
 
ใ“ใกใ‚‰ใฏ๏ผŒ่‡ชๅˆ†ใฎ๏ผฐ๏ผฃใฎ
Terminal 
ใ‚’ๅ‡บใ—
ใฆ๏ผŒ
่ชฌๆ˜Žใ—ใชใŒใ‚‰
     ruby โ€“e โ€œputs( (5+18)%26 )โ€ 
     ruby โ€“e โ€œputs( (11+18)%26 )โ€
ใ‚’ใ‚„ใฃใŸๅพŒใง๏ผŒ
่ฒ ใฎๆ•ฐใŒใฉใ†่กจใ•ใ‚Œใ‚‹ใ‹ใ‚’็คบใ—ใฆใฟใ›ใ‚‹ใ€‚ใใ‚Œใง็ญ”ใˆใธ
่ช˜ๅฐŽใ™ใ‚‹ใ€‚
ๅˆฅ็”ป้ขใฎไฝฟใ„ๆ–นใฎไพ‹๏ผˆใใฎ๏ผ‘๏ผ‰
 
iPad 
ใฎ็”ป้ขใ‚’ๅ‡บใ—ใฆ๏ผŒใใ“ใงๆ‰‹ๆ›ธใใง่ชฌๆ˜Žใ—ใฆใฟใ‚‹ใ€‚
โ€ป
ใ“ใฎๆŽˆๆฅญใฎใ“ใฎๅ ด้ขใงๅฟ…่ฆใงใฏใชใ„ใŒ๏ผŒไธ€ไพ‹ใจใ—ใฆๅฎŸๆผ”ใ—ใฆใฟใพใ™ใ€‚
ใ€€
Zoom 
ใซ 
iPad 
ใ‹ใ‚‰ใ‚‚ๅ…ฅใฃใฆใ„ใ‚‹ใจ๏ผˆๅˆฅใ‚ขใ‚ซใ‚ฆใƒณใƒˆๅ๏ผˆๅˆฅใซใคใใฃใŸ
ใ€€ใƒกใƒผใƒซใ‚ขใƒ‰ใƒฌใ‚น๏ผ‰ใง๏ผ‰ใ“ใฎใ‚ˆใ†ใซๆ‰‹ๆ›ธใใฎ่ชฌๆ˜Žใ‚‚ใงใใ‚‹๏ผŒใจใ„ใ†ไพ‹ใ€‚
Letโ€™s consider 
!!
Part 3.2.  Cryptanalysis
How to implement?
Complete the definition of subroutine โ€œdecโ€ for decryption.
def
 
dec
(k
, 
c
)
  
# prepare
   
code_a = 97
   leng = 
c
.length
   
# compute ciphertext
   a = 
c
.unpack("C*")
   b = Array.new(leng)
   for  i in 0..(leng-1)
      dist = a[i] - code_a
      if 0 <= dist && dist <= 25
         
b[i] =
      else
         b[i] = a[i]
      end
   end  
   
m
 = b.pack(โ€œC*โ€)
   
return
 
m
end
ใ€Œ
The Adventure of  the Dancing Men
ใ€
   Arthur Conan Doyle
https://221b.jp/h/danc.html
Letโ€™s consider 
!! 
(use 15 min.)
Google form
๏ผˆ
CSxxx_C3_12-Q2
๏ผ‰
https://forms.gle/a9TdHEr2kA3VwRj9A
b[i] = code_a + ((dist + k)%26))
Slide Note
Embed
Share

Cryptanalysis is a fundamental aspect of cryptography that involves decoding encrypted communications and messages. This topic delves into the basic cryptographic tools, such as the Caesar cipher, and explores how encryption and decryption functions work. By understanding cryptanalysis, you can analyze and break encrypted codes to reveal hidden information.

  • Cryptanalysis
  • Cryptography
  • Encryption
  • Decryption
  • Caesar Cipher

Uploaded on Sep 21, 2024 | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Introduction to Computer Science Topic 2 (Part 3) Goals of Topic 2 To learn what programming is. To learn some key programming techniques. Contents for Topic 2 (part 3) Function (or subroutine) Cryptanalysis Practice exercises 1. How to use arrays 2. Characters and strings, and how to use them 3. Cryptanalysis challenge

  2. What is cryptography? Part 3.2. Cryptanalysis Cryptography or cryptographic communication refers to communication encoded in such a way that you can t tell what the content of a communication text is even if you see it. Basic flow of cryptographic communication Cryptography is not only for communication; for example, we may use it when storing data. 2

  3. Let's define the basic cryptographic tools as functions. Part 3.2. Cryptanalysis Caesar cipher encryption function enc (encryption key ?, plaintext ?) = ciphertext for ? (obtained by shifting ? letters). decryption function dec (encryption key ?, ciphertext ?) = plaintext for ? (obtained by reverse shifting ? letters). 3

  4. What is cryptanalysis? Part 3.2. Cryptanalysis Cryptography or cryptographic communication refers to communication encoded in such a way that you can t tell what the content of a communication text is even if you see it. Basic flow of cryptographic communication 4

  5. Let's define the basic cryptographic tools as functions. Part 3.2. Cryptanalysis Caesar cipher encryption function enc (encryption key ?, plaintext ?) = ciphertext for ? (obtained by shifting ? letters). decryption function dec (encryption key ?, ciphertext ?) = plaintext for ? (obtained by reverse shifting ? letters). analysis function analysis (ciphertext ?) = plaintext for ?. 5

  6. Let's define the basic cryptographic tools as functions. Part 3.2. Cryptanalysis Caesar cipher Example encryption function enc (encryption key ?, plaintext ?) = ciphertext for ? (obtained by shifting ? letters). enc 3,"Good" = "Grrg" decryption function dec (encryption key ?, ciphertext ?) = plaintext for ? (obtained by reverse shifting ? letters). dec 3, "Grrg" = "Good" analysis function analysis (ciphertext ?) = plaintext for ?. analysis "Grrg" = "Good" 6

  7. How to implement? Part 3.2. Cryptanalysis Example $ ruby encrypt.rb God Gvk $ Encryption program encrypt.rb def enc(k, m) Creating a ciphertext c return c end #### program body##### k = 7 plaintext = gets.chomp ciphertext = enc(k, plaintext) puts(ciphertext) enc.rb from Part 3.1 What we want Input plaintext Function enc generates ciphertext Output ciphertext 7

  8. How to implement? Part 3.2. Cryptanalysis Decryption program decrypt.rb Encryption program encrypt.rb def dec(k, c) Converting to a plaintext m def enc(k, m) Creating a ciphertext c return m end #### program body##### k = 7 ciphertext = gets.chomp plaintext = dec(k, ciphertext) puts(plaintext) return c end #### program body##### k = 7 plaintext = gets.chomp ciphertext = enc(k, plaintext) puts(ciphertext) Let s consider !! 8

  9. How to implement? Part 3.2. Cryptanalysis Decryption program decrypt.rb Encryption program encrypt.rb def dec(k, c) Converting to a plaintext m def enc(k, m) Creating a ciphertext c return m end #### program body##### k = 7 ciphertext = gets.chomp plaintext = dec(k, ciphertext) puts(plaintext) return c end #### program body##### k = 7 plaintext = gets.chomp ciphertext = enc(k, plaintext) puts(ciphertext) On the PC of Sender A $ ruby encrypt.rb < message.txt > cryptomessage.txt $ $ ruby decrypt.rb < cryptomessage.txt This is a test message. Hello, everyone! How is the class? Are you enjoying this on-line lecture? On the PC of Receiver B 9

  10. How to implement? Part 3.2. Cryptanalysis Let s consider !! Complete the definition of subroutine dec for decryption. def enc(k, m) # prepare code_a = 97 leng = m.length # compute ciphertext a = m.unpack("C*") b = Array.new(leng) for i in 0..(leng-1) dist = a[i] - code_a if 0 <= dist && dist <= 25 b[i] = code_a + ((dist + k)%26)) else b[i] = a[i] end end c = b.pack( C* ) return c end hint: subroutine enc 10

  11. How to implement? Part 3.2. Cryptanalysis Let s consider !! Complete the definition of subroutine dec for decryption. def dec(k, c) # prepare code_a = 97 leng = c.length # compute ciphertext a = c.unpack("C*") b = Array.new(leng) for i in 0..(leng-1) dist = a[i] - code_a if 0 <= dist && dist <= 25 b[i] = else b[i] = a[i] end end m = b.pack( C* ) return m end b[i] = code_a + ((dist + k)%26)) 11

  12. How to implement? Part 3.2. Cryptanalysis Let s consider !! (use 15 min.) Let s consider !! Complete the definition of subroutine dec for decryption. def dec(k, c) # prepare code_a = 97 leng = c.length # compute ciphertext a = c.unpack("C*") b = Array.new(leng) for i in 0..(leng-1) dist = a[i] - code_a if 0 <= dist && dist <= 25 b[i] = else b[i] = a[i] end end m = b.pack( C* ) return m end Google form CSxxx_C3_12-Q2 https://forms.gle/a9TdHEr2kA3VwRj9A b[i] = code_a + ((dist + k)%26)) The Adventure of the Dancing Men Arthur Conan Doyle https://221b.jp/h/danc.html 13

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#