# Assignment 2. Classic/Block
Dinmukhametov Salavat
## Task 1
First of all, its have Enigma machine. Second, its tune rotors and plugboard.
If we want simulate, how Enigma machine works, we need more steps.
Then we press one of the button, electrical signal goes throw the entry wheel, through all 3 or 4 electrical rotors, and pass the reflector. The reflector returned by different path, back through the rotors and entry wheel, and goes throw wire which connected with new charackter and another lamp will turn on.
## Task 2
If we use 10 rotors, and select them from 50 unique rotors, all number of combination to select is C(10 50). All posible combinations of 10 rotors with 30 characters is 30^10. Also we can choose 5 different reflectors. All combinations to divide set into pairs is n for fisrt, n-2 for third, and formule is n\*(n-2)\*(n-4)\*..\*2.
So full formula is 5\*30^10\*C(10 50)\*30\*28\*...\*2. And answer is 1299567581457533697100087296000000000000000.
For Enigma machine formula is 1\*26^3\*C(3 5)\*26\*24\*..\*6 = 186788040671232000
## Task 3
I choose hashcat, because I easy to install and use. Also its popular one, so in Internet a lot of tutoials ans examples to use.
## Task 4
answer: **kissme**
```
hashcat -m 1800 -a 0 -o solved solve_hach 50000_passwords.txt
```
## Task 5
A block cipher is a method of produce ciphertext in which a cryptographic key and algorithm are applied to a block of data, in stream cipher are applied to each binary digit in a data stream, one bit at a time.
1. Block ciphers typically require more memory, since they work on larger chunks of data and often have "carry over" from previous blocks, whereas since stream ciphers work on only a few bits at a time they have relatively low memory requirements
2. Stream ciphers are typically faster than block ciphers.
3. Stream ciphers do not provide integrity protection or authentication, whereas some block ciphers (depending on mode) can provide integrity protection, in addition to confidentiality.
4. Stream ciphers are usually best for cases where the amount of data is either unknown, or continuous - such as network streams. Block ciphers, on the other hand, or more useful when the amount of data is pre-known - such as a file, data fields, or request/response protocols, such as HTTP where the length of the total message is known already at the beginning.
## Task 6
ECB - every block of text replace by ciphertext.
+) Encryption can be parallel.
-) Blocks of ciphertext can disappear and appear.
-) Encrypting the same block of plaintext using ECB mode always yields the same block of ciphertext(Can be encrypted by statistical analysis).
CBC - each block of plaintext (except the first) is added bitwise modulo 2 (XOR operation) with the previous encryption result.
+) if during transmission a change in one bit of ciphertext occurs, this error will propagate to the next block
-) Vulnerable to Oracle Attack
CFB - the encryption of the next block of plaintext, it is added modulo 2 with the encrypted (block cipher) encryption result of the previous block.
+) An error that occurs in the ciphertext during transmission (for example, due to interference) will make it impossible to decrypt both the block in which the error occurred and the one following it, but it does not apply to subsequent blocks.
Counter mode turns a block cipher into a stream cipher. It generates the next keystream block by encrypting successive values of a "counter". The counter can be any function which produces a sequence which is guaranteed not to repeat for a long time, although an actual increment-by-one counter is the simplest and most popular.
+) Encryption parallelizable
-) Сannot be used for real-time processing
## Task 7
Confusion - every bit of ciphertext should depends on several part of key, and hide the connection between them.
Diffusion - if we change one bit, then half of bits in ciphertext will changed. Also if we change one single bit in ciphertext, half of bits in the plaintext will be changed.