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'
- Size :
- 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
- size
- Last Chunk
- b'\x00\x00\x00\x00IEND\xaeB`\x82'
- with size 0, Type
IEND
, no data and CRCae 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 ...
Similar Kata:
Stats:
Created | Oct 23, 2021 |
Published | Oct 25, 2021 |
Warriors Trained | 249 |
Total Skips | 60 |
Total Code Submissions | 267 |
Total Times Completed | 32 |
Python Completions | 32 |
Total Stars | 16 |
% of votes with a positive feedback rating | 88% of 16 |
Total "Very Satisfied" Votes | 14 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |