Avatar
SubconsciousErosion_0x0
381dbcc7138eab9a71e814c57837c9d623f4036ec0240ef302330684ffc8b38f
I am a whole bag of special Transparent Pirate All the world Is a larp Don't take everything so seriously ⚠️ 🏷️ Nothing is for you

What if i added instead of subtracted

Using ASCII the shift count of 369 (by subtracting) the string "©.ÚËÎUÚb³Œ" becomes "³.Ó×ÑÓe³Û" - yes or no?

what is the output if the input is 10101001 101110 11011010 11001011 11001110 01010101 11011010 01100010 10110011 10001100?

And should I change program to Programme ?

#include

#include

#include

#include

#include

#include

#include

#include

int binaryToDecimal(const std::string& binary) {

int result = 0;

for (char c : binary) {

result = (result << 1) + (c - '0');

}

return result;

}

std::string binaryToHex(const std::string& binaryCode) {

std::bitset<8> bits(binaryToDecimal(binaryCode));

std::stringstream ss;

ss << std::hex << std::setw(2) << std::setfill('0') << static_cast(bits.to_ulong());

return ss.str();

}

std::string binaryToASCII(const std::string& binaryCode) {

std::string result;

for (size_t i = 0; i < binaryCode.length(); i += 8) {

std::bitset<8> bits(binaryCode.substr(i, 8));

char asciiChar = static_cast(bits.to_ulong());

result += asciiChar;

}

return result;

}

void decodeBinary(const std::string& binaryCode, std::string& originalInput, std::string& translation) {

std::cout << "May I present your 1s&0s Code: " << binaryCode << std::endl;

std::this_thread::sleep_for(std::chrono::seconds(2));

std::string asciiText = binaryToASCII(binaryCode);

std::cout << "Here's your Decoded ASCII: " << asciiText << std::endl;

originalInput = binaryCode;

translation = asciiText;

}

int main() {

std::string runProgram;

std::cout << "Wouldst thou like to runneth the program? (Yes/No): ";

std::cin >> runProgram;

if (runProgram == "Yes" || runProgram == "yes" || runProgram == "Y" || runProgram == "y") {

std::string binaryCode;

std::cout << "Giveth to me thine code of 1's and 0's: ";

std::cin.ignore();

std::getline(std::cin, binaryCode);

std::this_thread::sleep_for(std::chrono::seconds(2));

std::string hexCode = binaryToHex(binaryCode);

std::cout << "Ye ole Hex Code: 0x" << hexCode << std::endl;

std::this_thread::sleep_for(std::chrono::seconds(2));

std::string originalInput;

std::string translation;

decodeBinary(binaryCode, originalInput, translation);

std::cout << "Original Input: " << originalInput << std::endl;

std::cout << "Translation: " << translation << std::endl;

std::ofstream outputFile("what_you_had_said_was.txt");

if (outputFile.is_open()) {

outputFile << "1s&0s Code: " << binaryCode << std::endl;

outputFile << "Hex Code: 0x" << hexCode << std::endl;

outputFile << "Original Input: " << originalInput << std::endl;

outputFile << "Translation: " << translation << std::endl;

outputFile.close();

std::cout << "Translation saved to what_you_had_said_was.txt" << std::endl;

} else {

std::cout << "Apparently no one is home, I tried knockin'..." << std::endl;

}

std::string deleteEntry;

std::cout << "Wouldst thou like to delete the entry from the file? (Yes/No): ";

std::cin >> deleteEntry;

if (deleteEntry == "Yes" || deleteEntry == "yes" || deleteEntry == "Y" || deleteEntry == "y") {

if (std::remove("what_you_had_said_was.txt") == 0) {

std::cout << "Entry go poof." << std::endl;

} else {

std::cout << "For some reason unbeknownst to me, there has been an extreme malfunction. That file is still there." << std::endl;

}

}

} else {

std::cout << "Program terminated." << std::endl;

}

return 0;

}

// DAVE help! what should happen if I use this input:

01101000 01101111 01101100 01100001 00100000 01101101 01101001 00100000 01100001 01101101 01101001 01100111 01101111

// Dave - Is there anyway to improve this code?

#include

#include

#include

#include

#include

#include

#include

#include

unsigned char swapNibbles(unsigned char x) {

return ((x & 0x0F) << 4) | ((x & 0xF0) >> 4);

}

int binaryToDecimal(const std::string& binary) {

int result = 0;

for (char c : binary) {

result = (result << 1) + (c - '0');

}

return result;

}

std::string binaryToHex(const std::string& binaryCode) {

std::bitset<8> bits(binaryToDecimal(binaryCode));

std::stringstream ss;

ss << std::hex << std::setw(2) << std::setfill('0') << static_cast(bits.to_ulong());

return ss.str();

}

std::string hexToBinary(const std::string& hexCode) {

std::bitset<8> binary(std::stoi(hexCode, nullptr, 16));

return binary.to_string();

}

std::string binaryToASCII(const std::string& binaryCode) {

std::string result;

for (size_t i = 0; i < binaryCode.length(); i += 8) {

std::bitset<8> bits(binaryCode.substr(i, 8));

char asciiChar = static_cast(bits.to_ulong());

result += asciiChar;

}

return result;

}

void decodeHex(const std::string& hexCode, std::string& originalInput) {

std::string binaryCode = hexToBinary(hexCode);

std::cout << "Binary Code: " << binaryCode << std::endl;

std::this_thread::sleep_for(std::chrono::seconds(2));

std::string asciiText = binaryToASCII(binaryCode);

std::cout << "Decoded ASCII: " << asciiText << std::endl;

originalInput = binaryCode;

}

int main() {

std::string runProgram;

std::cout << "Would you like to run the program? (Y/N): ";

std::cin >> runProgram;

if (runProgram == "Yes" || runProgram == "yes" || runProgram == "Y" || runProgram == "y") {

std::string binaryCode;

std::cout << "Enter binary code: ";

std::cin.ignore(); // Ignore the newline character from previous input

std::getline(std::cin, binaryCode);

std::this_thread::sleep_for(std::chrono::seconds(2));

std::string hexCode = binaryToHex(binaryCode);

std::cout << "Hex Code: 0x" << hexCode << std::endl;

std::this_thread::sleep_for(std::chrono::seconds(2));

std::string originalInput;

decodeHex(hexCode, originalInput);

std::cout << "Original Input: " << binaryToASCII(originalInput) << std::endl;

// Store the input and translation in a file

std::ofstream outputFile("translation.txt");

if (outputFile.is_open()) {

outputFile << "Input: " << binaryCode << std::endl;

outputFile << "Hex: 0x" << hexCode << std::endl;

outputFile << "Original Input: " << binaryToASCII(originalInput) << std::endl;

outputFile.close();

std::cout << "Translation of original input: " << std::endl;

} else {

std::cout << "Something has gone horribly wrong ." << std::endl;

}

} else {

std::cout << "Program brrrr." << std::endl;

}

return 0;

}

Dave what can I do to make this better?

#include

#include

#include

#include

#include

#include

#include

unsigned char swapNibbles(unsigned char x) {

return ((x & 0x0F) << 4) | ((x & 0xF0) >> 4);

}

int binaryToDecimal(const std::string& binary) {

int result = 0;

for (char c : binary) {

result = (result << 1) + (c - '0');

}

return result;

}

std::string binaryToHex(const std::string& binaryCode) {

std::bitset<8> bits(binaryToDecimal(binaryCode));

std::stringstream ss;

ss << std::hex << std::setw(2) << std::setfill('0') << static_cast(bits.to_ulong());

return ss.str();

}

std::string hexToBinary(const std::string& hexCode) {

std::bitset<8> binary(std::stoi(hexCode, nullptr, 16));

return binary.to_string();

}

std::string binaryToASCII(const std::string& binaryCode) {

std::string result;

for (size_t i = 0; i < binaryCode.length(); i += 8) {

std::bitset<8> bits(binaryCode.substr(i, 8));

char asciiChar = static_cast(bits.to_ulong());

result += asciiChar;

}

return result;

}

void decodeHex(const std::string& hexCode) {

std::string binaryCode = hexToBinary(hexCode);

std::cout << "Binary Code: " << binaryCode << std::endl;

std::this_thread::sleep_for(std::chrono::seconds(2)); // Pause for 2 seconds

std::string asciiText = binaryToASCII(binaryCode);

std::cout << "Decoded ASCII: " << asciiText << std::endl;

}

int main() {

std::string runProgram;

std::cout << "Would you like to run the program? (Yes/No): ";

std::cin >> runProgram;

if (runProgram == "Yes" || runProgram == "yes" || runProgram == "Y" || runProgram == "y") {

std::string binaryCode;

std::cout << "Enter binary code: ";

std::cin >> binaryCode;

std::this_thread::sleep_for(std::chrono::seconds(2)); // Pause for 2 seconds

std::string hexCode = binaryToHex(binaryCode);

std::cout << "Hex Code: 0x" << hexCode << std::endl;

std::this_thread::sleep_for(std::chrono::seconds(2)); // Pause for 2 seconds

decodeHex(hexCode);

} else {

std::cout << "Program brrrr." << std::endl;

}

return 0;

}

Output:

Would you like to run the program? (Yes/No): y

Enter binary code:

(input)10011010110100110010101010101101001

Hex Code: 0x69

Binary Code: 01101001

Decoded ASCII: i

...Program finished with exit code 0

Press ENTER to exit console.

Apparently closing a statement -_- .... *Drags feet to get back to working on something stupid*

(when someone takes a really long time to message back "k")

#include

#include

#include

#include

#include

#include

#include

unsigned char swapNibbles(unsigned char x) {

return ((x & 0x0F) << 4) | ((x & 0xF0) >> 4);

}

int binaryToDecimal(const std::string& binary) {

int result = 0;

for (char c : binary) {

result = (result << 1) + (c - '0');

}

return result;

}

std::string hexToBinary(const std::string& hexCode) {

std::bitset<8> binary(std::stoi(hexCode, nullptr, 16));

return binary.to_string();

}

std::string binaryToASCII(const std::string& binaryCode) {

std::string result;

for (size_t i = 0; i < binaryCode.length(); i += 8) {

std::bitset<8> bits(binaryCode.substr(i, 8));

char asciiChar = static_cast(bits.to_ulong());

result += asciiChar;

}

return result;

}

void decodeHex(const std::string& hexCode) {

std::string binaryCode = hexToBinary(hexCode);

std::cout << "Binary Code: " << binaryCode << std::endl;

std::string asciiText = binaryToASCII(binaryCode);

std::cout << "Decoded ASCII: " << asciiText << std::endl;

}

int main() {

std::string runProgram;

std::cout << "Would you like to run the program? (Yes/No): ";

std::cin >> runProgram;

if (runProgram == "Yes" || runProgram == "yes" || runProgram == "Y" || runProgram == "y") {

std::string binaryCode = "101011001101011001000101101001001101101";

unsigned char myByte = static_cast(binaryToDecimal(binaryCode));

unsigned char swappedByte = swapNibbles(myByte);

std::cout << "Swapped Byte (Hex): 0x" << std::hex << std::setw(2) << std::setfill('0') << static_cast(swappedByte) << std::endl;

std::this_thread::sleep_for(std::chrono::seconds(2)); // Pause for 2 seconds

std::string hexCode = "4B";

std::string decodeInput;

std::cout << "Would you like to decode the hex value? (Yes/No): ";

std::cin >> decodeInput;

if (decodeInput == "Yes" || decodeInput == "yes" || decodeInput == "Y" || decodeInput == "y") {

decodeHex(hexCode);

std::this_thread::sleep_for(std::chrono::seconds(2)); // Pause for 2 seconds

}

} else {

std::cout << "Program brrrr." << std::endl;

}

return 0;

}

Only Shiva knows how far we'll take this........