Last active
January 17, 2026 16:59
-
-
Save LightningStalker/98cb340466498219b25f5a7a425d7ece to your computer and use it in GitHub Desktop.
Another demo for the C++ hexdump of previous gist (need the hxd.hpp)
This file contains hidden or 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
| /* Compile with $ g++ -o fl fl.cpp | |
| * Project Crew™ 12/28/2025 | |
| */ | |
| #include <iostream> | |
| #include <iomanip> | |
| using namespace std; | |
| #include "fl.hpp" | |
| #include "hxd.hpp" | |
| //#define DBG 1 | |
| #define MYB "Lorem ipsum dolor sit amet, " \ | |
| "consectetuer adipiscing elit." | |
| void | |
| fl (unsigned char *myb, unsigned long int mybsize) | |
| { | |
| /* turn the string to unprintable junk chars */ | |
| unsigned long int c; | |
| /* register */ uint8_t t; | |
| for(c = 0; c < mybsize - 1; c++) | |
| { | |
| #ifdef DBG | |
| cout << c << ' '; | |
| #endif | |
| t = myb[c]; // take each char and ... | |
| t += A; // add (pretty obvious) | |
| t = lrot8(t, S); // bitwise nybble swap | |
| t ^= W; // ... NOT | |
| t -= A; // subtract | |
| myb[c] = t; // store back to array | |
| } | |
| } | |
| int | |
| main() | |
| { | |
| unsigned char myb[] = MYB; | |
| unsigned long int mybsize = sizeof(myb); | |
| fl(myb, mybsize); | |
| /* take a lQQk at what we got */ | |
| hxd(myb, mybsize); | |
| cout << "\n\n"; | |
| cout << '"' << myb << '"' << endl; | |
| } |
This file contains hidden or 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
| #ifndef CHAR_BIT | |
| #define CHAR_BIT 8 | |
| #endif | |
| #define A 3 // temp + A... - A | |
| #define S 4 // byte swap | |
| #define W -1 // temp xor 0xff (-1) = NOT temp | |
| /* 8-bit bitwise rotate, should compile to a ror/rol (x86) | |
| * How we rotate before the std::bit in C++20 */ | |
| static inline uint8_t | |
| lrot8 (uint8_t c, unsigned int n) | |
| { | |
| const unsigned int mask = (CHAR_BIT*sizeof(c) - 1); | |
| // assert ( (c<=mask) &&"rotate by type width or more"); | |
| n &= mask; // o <= N | |
| return (c << n) | (c >> ( (-n) & mask) ); // do rotate | |
| /* flip the << shift >> to rotate the other way */ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment