bkcrack 1.7.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
14class BaseError : public std::runtime_error
15{
16public:
18 explicit BaseError(const std::string& type, const std::string& description);
19};
20
21// utility functions
22
24constexpr auto lsb(std::uint32_t x) -> std::uint8_t
25{
26 return x;
27}
28
30constexpr auto msb(std::uint32_t x) -> std::uint8_t
31{
32 return x >> 24;
33}
34
35// constants
36
38template <int begin, int end>
39constexpr auto mask = std::uint32_t{~0u << begin & ~0u >> (32 - end)};
40
50template <int x>
51constexpr auto maxdiff = std::uint32_t{mask<0, x> + 0xff};
52
53#endif // BKCRACK_TYPES_HPP
BaseError(const std::string &type, const std::string &description)
Constructor.
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
constexpr auto lsb(std::uint32_t x) -> std::uint8_t
Definition types.hpp:24
constexpr auto mask
Constant value for bit masking.
Definition types.hpp:39
constexpr auto msb(std::uint32_t x) -> std::uint8_t
Definition types.hpp:30