Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to reverse a QByteArray
Forum Updated to NodeBB v4.3 + New Features

How to reverse a QByteArray

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 6.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hollywood33
    wrote on last edited by VRonin
    #1

    Hi! I have this code:
    QByteArray a = "Test Data"; QByteArray aBase64 = a.toBase64(); qDebug() << aBase64;

    Upon executon, I get this: VGVzdCBEYXRh. How to reverse the resulting code?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you thinking about QByteArray::fromBase64 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • H Offline
        H Offline
        Hollywood33
        wrote on last edited by
        #3

        I want to get the resulting code written backwards: hRXY....

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4
          QByteArray a = "Test Data";
          QByteArray aBase64 = a.toBase64();
          QByteArray b(aBase64.size(),0);
          std::copy(aBase64.crbegin(),aBase64.crend(),b.begin());
          qDebug() << aBase64;
          qDebug() << b;
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          H 2 Replies Last reply
          7
          • VRoninV VRonin
            QByteArray a = "Test Data";
            QByteArray aBase64 = a.toBase64();
            QByteArray b(aBase64.size(),0);
            std::copy(aBase64.crbegin(),aBase64.crend(),b.begin());
            qDebug() << aBase64;
            qDebug() << b;
            
            H Offline
            H Offline
            Hollywood33
            wrote on last edited by
            #5

            @VRonin Thank you!

            1 Reply Last reply
            0
            • VRoninV VRonin
              QByteArray a = "Test Data";
              QByteArray aBase64 = a.toBase64();
              QByteArray b(aBase64.size(),0);
              std::copy(aBase64.crbegin(),aBase64.crend(),b.begin());
              qDebug() << aBase64;
              qDebug() << b;
              
              H Offline
              H Offline
              Hollywood33
              wrote on last edited by
              #6

              @VRonin class QByteArray' has no member named 'crbegin

              VRoninV 1 Reply Last reply
              0
              • H Hollywood33

                @VRonin class QByteArray' has no member named 'crbegin

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #7

                @Hollywood33 that method was added ~2 years ago: http://doc.qt.io/qt-5/qbytearray.html#crbegin

                What version of Qt are you using?

                Workaround:

                QByteArray a = "Test Data";
                QByteArray aBase64 = a.toBase64();
                QByteArray b;
                b.reserve(aBase64.size());
                for(int i= aBase64.size()-1;i>=0;--i)
                b.append(aBase64.at(i));
                qDebug() << aBase64;
                qDebug() << b;
                

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                H 1 Reply Last reply
                4
                • VRoninV VRonin

                  @Hollywood33 that method was added ~2 years ago: http://doc.qt.io/qt-5/qbytearray.html#crbegin

                  What version of Qt are you using?

                  Workaround:

                  QByteArray a = "Test Data";
                  QByteArray aBase64 = a.toBase64();
                  QByteArray b;
                  b.reserve(aBase64.size());
                  for(int i= aBase64.size()-1;i>=0;--i)
                  b.append(aBase64.at(i));
                  qDebug() << aBase64;
                  qDebug() << b;
                  
                  H Offline
                  H Offline
                  Hollywood33
                  wrote on last edited by
                  #8

                  @VRonin This works! Thanks!

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved