-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
76 changed files
with
8,137 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Base Encoding & Decoding Functions | ||
|
||
## encodeBase16 | ||
|
||
**Brief:** Encodes a vector of unsigned characters into a Base16 string. | ||
|
||
This function takes a vector of unsigned characters and encodes it into a Base16 string representation. Base16 encoding, also known as hexadecimal encoding, represents each byte in the input data as a pair of hexadecimal digits (0-9, A-F). | ||
|
||
- **Parameters:** | ||
|
||
- `data`: The vector of unsigned characters to be encoded. | ||
|
||
- **Return:** | ||
- The Base16 encoded string. | ||
|
||
## decodeBase16 | ||
|
||
**Brief:** Decodes a Base16 string into a vector of unsigned characters. | ||
|
||
This function takes a Base16 encoded string and decodes it into a vector of unsigned characters. Base16 encoding, also known as hexadecimal encoding, represents each byte in the input data as a pair of hexadecimal digits (0-9, A-F). | ||
|
||
- **Parameters:** | ||
|
||
- `data`: The Base16 encoded string to be decoded. | ||
|
||
- **Return:** | ||
- The decoded vector of unsigned characters. | ||
|
||
## encodeBase32 | ||
|
||
**Brief:** Encodes a string to Base32. | ||
|
||
- **Parameters:** | ||
|
||
- `input`: The string to encode. | ||
|
||
- **Return:** | ||
- The encoded string. | ||
|
||
## decodeBase32 | ||
|
||
**Brief:** Decodes a Base32 string. | ||
|
||
- **Parameters:** | ||
|
||
- `input`: The string to decode. | ||
|
||
- **Return:** | ||
- The decoded string. | ||
|
||
## base64Encode | ||
|
||
**Brief:** Base64 encoding function. | ||
|
||
- **Parameters:** | ||
|
||
- `bytes_to_encode`: Data to be encoded. | ||
|
||
- **Return:** | ||
- Encoded string. | ||
|
||
## base64Decode | ||
|
||
**Brief:** Base64 decoding function. | ||
|
||
- **Parameters:** | ||
|
||
- `encoded_string`: String to decode. | ||
|
||
- **Return:** | ||
- Decoded data as a vector of unsigned characters. | ||
|
||
## encodeBase85 | ||
|
||
**Brief:** Encodes a vector of unsigned characters into a Base85 string. | ||
|
||
This function takes a vector of unsigned characters and encodes it into a Base85 string representation. Base85 encoding is a binary-to-text encoding scheme that encodes 4 bytes into 5 ASCII characters. | ||
|
||
- **Parameters:** | ||
|
||
- `data`: The vector of unsigned characters to be encoded. | ||
|
||
- **Return:** | ||
- The Base85 encoded string. | ||
|
||
## decodeBase85 | ||
|
||
**Brief:** Decodes a Base85 string into a vector of unsigned characters. | ||
|
||
This function takes a Base85 encoded string and decodes it into a vector of unsigned characters. Base85 encoding is a binary-to-text encoding scheme that encodes 4 bytes into 5 ASCII characters. | ||
|
||
- **Parameters:** | ||
|
||
- `data`: The Base85 encoded string to be decoded. | ||
|
||
- **Return:** | ||
- The decoded vector of unsigned characters. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Fraction Class | ||
|
||
The Fraction class represents a fraction and provides basic fraction operations and functionalities. | ||
|
||
## Member Functions | ||
|
||
### Constructors | ||
|
||
#### `Fraction(int num_value, int den_value)` | ||
|
||
Constructs a fraction object with the given numerator and denominator. | ||
|
||
#### `Fraction(int num_value)` | ||
|
||
Constructs a fraction object with the given integer as the numerator, defaulting the denominator to 1. | ||
|
||
#### `Fraction(const char *str)` | ||
|
||
Constructs a fraction object from the given string. | ||
|
||
#### `Fraction()` | ||
|
||
Default constructor that constructs a fraction object with a value of 0. | ||
|
||
### Member Methods | ||
|
||
#### `int getNumerator() const` | ||
|
||
Gets the numerator of the fraction. | ||
|
||
#### `int getDenominator() const` | ||
|
||
Gets the denominator of the fraction. | ||
|
||
#### `void alterValue(int num_value, int den_value)` | ||
|
||
Changes the value of the fraction to the specified numerator and denominator. | ||
|
||
#### `void alterValue(const Fraction &f)` | ||
|
||
Changes the value of the fraction to the value of another fraction object. | ||
|
||
#### `Fraction inverse()` | ||
|
||
Returns the reciprocal of the fraction. | ||
|
||
### Operator Overloading | ||
|
||
#### `+`, `-`, `*`, `/` | ||
|
||
Implements addition, subtraction, multiplication, and division for fractions. | ||
|
||
#### `==`, `!=`, `>`, `>=`, `<`, `<=` | ||
|
||
Implements comparison operators for fractions. | ||
|
||
#### `<<`, `>>` | ||
|
||
Implements input and output stream operations for fraction objects. | ||
|
||
#### Negation Operator | ||
|
||
Negates a fraction to its opposite value. | ||
|
||
### Friend Functions | ||
|
||
#### `operator>>` | ||
|
||
Reads a fraction object's value from the input stream. | ||
|
||
#### `operator<<` | ||
|
||
Writes a fraction object's value to the output stream. | ||
|
||
## Examples | ||
|
||
```cpp | ||
Fraction f1(1, 2); | ||
Fraction f2(3, 4); | ||
Fraction result = f1 + f2; // result = 5/4 | ||
std::cout << result; // Output: 5/4 | ||
``` | ||
```cpp | ||
Fraction f1(2, 3); | ||
Fraction f2(1, 6); | ||
bool isEqual = (f1 == f2); // isEqual = false | ||
``` | ||
|
||
```cpp | ||
Fraction f1(3, 5); | ||
Fraction f2 = -f1; // f2 = -3/5 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Huffman Coding | ||
|
||
## HuffmanNode Struct | ||
|
||
**Brief:** Represents a node in a Huffman tree. | ||
|
||
- `char data`: The character stored in the node. | ||
- `int frequency`: The frequency of the node. | ||
- `HuffmanNode *left`: Pointer to the left child node. | ||
- `HuffmanNode *right`: Pointer to the right child node. | ||
|
||
### Constructor | ||
|
||
- **Parameters:** | ||
- `data`: The character to be stored in the node. | ||
- `frequency`: The frequency of the node. | ||
|
||
## createHuffmanTree | ||
|
||
**Brief:** Creates a Huffman tree. | ||
|
||
- **Parameters:** | ||
|
||
- `frequencies`: Table of character frequencies. | ||
|
||
- **Return:** | ||
- `HuffmanNode*`: Pointer to the root node of the Huffman tree. | ||
|
||
## generateHuffmanCodes | ||
|
||
**Brief:** Recursively generates Huffman codes. | ||
|
||
- **Parameters:** | ||
- `root`: Pointer to the current node. | ||
- `code`: Current code for the node. | ||
- `huffmanCodes`: Map to store the Huffman codes. | ||
|
||
## compressText | ||
|
||
**Brief:** Compresses text using Huffman coding. | ||
|
||
- **Parameters:** | ||
|
||
- `text`: Text to be compressed. | ||
- `huffmanCodes`: Map containing the Huffman codes. | ||
|
||
- **Return:** | ||
- `std::string`: Compressed text. | ||
|
||
## decompressText | ||
|
||
**Brief:** Decompresses text using Huffman coding. | ||
|
||
- **Parameters:** | ||
|
||
- `compressedText`: Compressed text. | ||
- `root`: Pointer to the root node of the Huffman tree. | ||
|
||
- **Return:** | ||
- `std::string`: Decompressed text. | ||
|
||
### Example Usage | ||
|
||
```cpp | ||
#include <unordered_map> | ||
#include <string> | ||
|
||
// Define character frequencies | ||
std::unordered_map<char, int> frequencies = { | ||
{'a', 10}, | ||
{'b', 15}, | ||
{'c', 30}, | ||
{'d', 5}, | ||
{'e', 20} | ||
}; | ||
|
||
// Create Huffman tree | ||
HuffmanNode *root = createHuffmanTree(frequencies); | ||
|
||
// Generate Huffman codes | ||
std::unordered_map<char, std::string> huffmanCodes; | ||
generateHuffmanCodes(root, "", huffmanCodes); | ||
|
||
// Compress text using Huffman coding | ||
std::string text = "abcde"; | ||
std::string compressedText = compressText(text, huffmanCodes); | ||
|
||
// Decompress text using Huffman coding | ||
std::string decompressedText = decompressText(compressedText, root); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# MD5 Class | ||
|
||
The MD5 class provides functionality to calculate the MD5 hash of input data using the MD5 algorithm. | ||
|
||
## Member Functions | ||
|
||
### Public Methods | ||
|
||
#### `static std::string encrypt(const std::string &input)` | ||
|
||
Encrypts the input string using the MD5 algorithm and returns the MD5 hash of the input string. | ||
|
||
### Private Methods | ||
|
||
#### `void init()` | ||
|
||
Initializes internal variables and a buffer for MD5 computation. | ||
|
||
#### `void update(const std::string &input)` | ||
|
||
Updates the MD5 computation with additional input data. | ||
|
||
#### `std::string finalize()` | ||
|
||
Finalizes the MD5 computation and returns the resulting hash of all the input data provided so far. | ||
|
||
#### `void processBlock(const uint8_t *block)` | ||
|
||
Processes a 64-byte block of input data. | ||
|
||
### Static Helper Functions | ||
|
||
#### `static uint32_t F(uint32_t x, uint32_t y, uint32_t z)` | ||
|
||
The F function for the MD5 algorithm. | ||
|
||
#### `static uint32_t G(uint32_t x, uint32_t y, uint32_t z)` | ||
|
||
The G function for the MD5 algorithm. | ||
|
||
#### `static uint32_t H(uint32_t x, uint32_t y, uint32_t z)` | ||
|
||
The H function for the MD5 algorithm. | ||
|
||
#### `static uint32_t I(uint32_t x, uint32_t y, uint32_t z)` | ||
|
||
The I function for the MD5 algorithm. | ||
|
||
#### `static uint32_t leftRotate(uint32_t x, uint32_t n)` | ||
|
||
Performs a left rotate operation on the input. | ||
|
||
#### `static uint32_t reverseBytes(uint32_t x)` | ||
|
||
Reverses the bytes in the input. | ||
|
||
## Member Variables | ||
|
||
- `uint32_t _a, _b, _c, _d`: Internal state variables for MD5 computation. | ||
- `uint64_t _count`: Total count of input bits. | ||
- `std::vector<uint8_t> _buffer`: Buffer for input data. | ||
|
||
## Example Usage | ||
|
||
```cpp | ||
#include "MD5.h" | ||
#include <iostream> | ||
|
||
int main() { | ||
std::string input = "Hello, World!"; | ||
std::string md5Hash = MD5::encrypt(input); | ||
std::cout << "MD5 Hash: " << md5Hash << std::endl; | ||
return 0; | ||
} | ||
``` |
Oops, something went wrong.