bkcrack: include/bkcrack/types.hpp Source File

bkcrack 1.8.1 Crack legacy zip encryption with Biham and Kocher's known plaintext attack.

types.hpp
Go to the documentation of this file.
1#ifndef BKCRACK_TYPES_HPP
2#define BKCRACK_TYPES_HPP
3
6
7#include <array>
8#include <cstdint>
9#include <stdexcept>
10#include <string>
11#include <vector>
12
14 class BaseError : public std::runtime_error
15{
16public:
18 explicit BaseError(const std::string& type, const std::string& description);
19};
20
21// utility functions
22
24 constexpr auto lsb(std::uint32_t x) -> std::uint8_t
25{
26 return x;
27}
28
30 constexpr auto msb(std::uint32_t x) -> std::uint8_t
31{
32 return x >> 24;
33}
34
35// constants
36
38template <int begin, int end>
39 constexpr auto mask = std::uint32_t{~0u << begin & ~0u >> (32 - end)};
40
50template <int x>
51 constexpr auto maxdiff = std::uint32_t{mask<0, x> + 0xff};
52
53#endif // BKCRACK_TYPES_HPP
BaseError::BaseError
BaseError(const std::string &type, const std::string &description)
Constructor.
maxdiff
constexpr auto maxdiff
Maximum difference between 32-bits integers A and B[x,32) knowing that A = B + b and b is a byte.
Definition types.hpp:51
lsb
constexpr auto lsb(std::uint32_t x) -> std::uint8_t
Definition types.hpp:24
mask
constexpr auto mask
Constant value for bit masking.
Definition types.hpp:39
msb
constexpr auto msb(std::uint32_t x) -> std::uint8_t
Definition types.hpp:30