convert a cipher to binary

Suppose I have this ciphertext:

1
2
╟êZÇN^Θ·@▒cI┴F√wî▀-:  ⌡┤╡╨╨ETh«╣å"▒7┌ΦWU<═êâº╝7Rσ&╥,òN║P%╕╠WεYAîτ▄k─&V╜│k╝úΦwC√╩ú╕;     V       çü_e(gdp=α≤╒$@
>▒Ya∩> 


How can I convert it to binary? I am so confused. I couldn't find anything that works.

What do you mean binary? You want to print 001001011100101010101010110 type stuff? Or you want to re-encrypt it to a full byte including unprintable chars? Or something else?
I want to represent each character in binary (10101010101 stuff, yes).
You can use std::bitset.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <bitset>
#include <iostream>
#include <string>

int main()
{
    constexpr std::size_t wchar_bits{ sizeof( wchar_t ) * 8 };
    std::cout << "wchar_t bits = " << wchar_bits << "\n\n";
    
    std::wstring cipher{ L"╟êZÇN^Θ·@▒cI┴F√wî▀-:  ⌡┤╡╨╨ETh«╣å\"▒7┌ΦWU<═êâº╝7Rσ&╥,òN║P%╕╠WεYAîτ▄k─&V╜│k╝úΦwC√╩ú╕;     V       çü_e(gdp=α≤╒$@>▒Ya∩> " };
    for( wchar_t wc : cipher )
        std::cout << std::bitset<wchar_bits>{ static_cast<unsigned long long>( wc ) } << '\n';
}

I want a function that returns the output. How can I do that?

What will the function type be?

What will the function type be?

Well that depends on how you want to handle the binary string. std::bitset has a to_string() member function, so you could concatenate the strings to one long string. You could also have a std::vector<std::string> to store the binary interpretation of each character. I've given you the code that you asked for, it's up to you how you want to implement it.
Topic archived. No new replies allowed.