Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8786299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:35:04+00:00 2026-06-13T21:35:04+00:00

I have a function that operates on 128-bit blocks of data from an arbitrary-length

  • 0

I have a function that operates on 128-bit blocks of data from an arbitrary-length string. If the string is not evenly divisible into chunks of 128 bits, it will be padded accordingly.

The purpose is to transform the data in the string that is fed into the function.

I initially thought of looping through the string a such:

//This might have stupid errors.  Hopefully it stillg gets the point across.
for (int i = 0; i < strn.size(); i += 16)
{
    string block = strn.substr(i, i + 15);
    strn.replace(i, i + 15, block);
}

I guess this would work, but I’m thinking there must be a more elegant way to do this. One idea that came to mind was to encapsulate strn in a class and implement my own iterator that can read its contents in 128-bit chunks. This is appealing because the constructor could handle padding and some of the functions I currently use could be made private, thus avoiding potential misuse. Does this seem like a fruitful approach? If so, how does one go about implementing his own iterator? Detailed explanations are most welcome, as I’m very inexperienced with C++.

Are there other, perhaps better, approaches?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:35:07+00:00Added an answer on June 13, 2026 at 9:35 pm

    There are many approaches. One of the more simple and straightforward ones would be like this:
    you can create your own type sized exactly 128 bit; simple struct will do the job.

    typedef struct
    {
        char buf[16];
    } _128bit;
    

    And use it to iterate over your string.
    Cast the beginning of your string to this struct type:_128bit* start = (_128bit*)buffer; and start iterating with it, using the integral pointer arithmetic. All operations on start will operate in terms of its size. E.g. ,start++ will move 128 bits forward; start-- will move 128 bit back. Once you’re at the desired position, recast it to the desired type and perform your manipulations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Java code I have function that gets file from the client in
I have a function that takes an input string and then runs the string
I have a join function that operates on STL strings. I want to be
Assume that I have a MemoryStream and function that operates on bytes. Current code
I have a function that, in the simplest of cases, operates on an iterable
I have a bit of an issue with a toggle visibility function which operates
i have a function in Lua that operates on a table, repeatedly adding entries
I have a templated function that operates on a template-type variable, and if the
I have a Haskell function that operates on a single file to produce a
I have a dropdown box that operates with the following: $(document).on(mouseenter mouseleave, #dropdown, function(event){

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.