36 lines
761 B
Markdown
36 lines
761 B
Markdown
|
Here's a home-brewed stream cipher:
|
||
|
|
||
|
```
|
||
|
uint64_t next(uint64_t x)
|
||
|
{
|
||
|
return (x << 12) ^ ((x >> 12) + 1);
|
||
|
}
|
||
|
|
||
|
typedef uint8_t (*hash_func_t)(uint64_t x);
|
||
|
|
||
|
hash_func_t hash;
|
||
|
uint64_t state;
|
||
|
|
||
|
void initialize(hash_func_t h, uint64_t iv)
|
||
|
{
|
||
|
hash = h;
|
||
|
state = iv;
|
||
|
}
|
||
|
|
||
|
uint8_t get_byte(void)
|
||
|
{
|
||
|
uint8_t b = hash(state);
|
||
|
state = next(state);
|
||
|
return b;
|
||
|
}
|
||
|
```
|
||
|
|
||
|
It's extra secure because even some of its code is secret.
|
||
|
|
||
|
Here's a (ASCII) message, containing the flag, encrypted with this method: the ciphertext is the plaintext xor-ed with a stream of bytes generated using these functions, starting with a secret, well-chosen hash function and a random initialization vector.
|
||
|
|
||
|
Flag: the format as commonly used, eg. CCTF{flagitself}
|
||
|
|
||
|
//Type: Cryptography
|
||
|
//Author: SI
|