5 kyu

Break Caesar cipher variation : PNG image

Description:

introduction

In this kata you can learn

  • How to deal with bytes files in python
  • Caesar code
  • Convert bytes to int
  • Few things about PNG format

Caesar code

In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.

In our kata we deal with bytes not letters.
Each byte is shift by a number between 0 and 255.

Few words about PNG Format

A PNG file starts with an 8-byte signature (in hexadecimal: 89 50 4E 47 0D 0A 1A 0A).
After the header, comes a series of chunks, each of which conveys certain information about the image.

A chunk consists of four parts:

  • LENGTH : length of data (4 bytes, big-endian)
  • TYPE : The name of the chunk (4 bytes). In the image we are going to use Name can be (IHDR PLTE IDAT IEND)
  • DATA : (length bytes)
  • CRC : (cyclic redundancy code/checksum; 4 bytes)

For this 1 orange pixel png

b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\rIDAT\x08\x99c\xf8\xbf\x94\xe1?\x00\x06\xef\x02\xa4+\x9by\xe0\x00\x00\x00\x00IEND\xaeB`\x82'

We have :

  • The signature \x89PNG\r\n\x1a\n in hexa :89 50 4E 47 0D 0A 1A 0A
  • First Chunk
    • b'\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89'
    • In hexa :00 00 00 0d 49 48 44 52 00 00 00 01 00 00 00 01 08 06 00 00 00 1f 15 c4 89
    • With:
      • Size : 00 00 00 0d = 13
      • Type : 49 48 44 52 = b'IHDR'
      • Data : '00 00 00 01 00 00 00 01 08 06 00 00 00'
      • CRC : `1f 15 c4 89'
  • Second Chunk
    • b'\x00\x00\x00\rIDAT\x08\x99c\xf8\xbf\x94\xe1?\x00\x06\xef\x02\xa4+\x9by\xe0'
      • size 00 00 00 0d
      • Type 49 44 41 54 = IDAT
      • Data 08 99 63 f8 bf 94 e1 3f 00 06 ef 02 a4
      • CRC 2b 9b 79 e0
  • Last Chunk
    • b'\x00\x00\x00\x00IEND\xaeB`\x82'
    • with size 0, Type IEND, no data and CRC ae 42 60 82

The challenge

You will have de decode a serie of PNG images. PNG image will be encrypted like this :

  • The signature is let untouched
  • Each chunk is encrypted with cesar code with its own key (amount of shift)

Have fun ...

Cryptography
Fundamentals

More By Author:

Check out these other kata created by tchai2

Stats:

CreatedOct 23, 2021
PublishedOct 25, 2021
Warriors Trained249
Total Skips60
Total Code Submissions267
Total Times Completed32
Python Completions32
Total Stars16
% of votes with a positive feedback rating88% of 16
Total "Very Satisfied" Votes14
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes2
Total Rank Assessments5
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • tchai2 Avatar
  • lechevalier Avatar
  • Blind4Basics Avatar
Ad