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 7993909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:59:35+00:00 2026-06-04T13:59:35+00:00

Now I am learning cryptograpgy. So, (for practice and for fun), I have decided

  • 0

Now I am learning cryptograpgy. So, (for practice and for fun), I have decided to implement AES. I got stuck in one point (mixing columns here is my code):

typedef vector< vector<short> > vvector;

short mixBox[4][4] = 
{
    {0x02, 0x03, 0x01, 0x01},
    {0x01, 0x02, 0x03, 0x01},
    {0x01, 0x01, 0x02, 0x03},
    {0x03, 0x01, 0x01, 0x02}
};

short gfMultiply(short h1, short h2)
{
    //h1 can 0x01, 0x02 or 0x03
}

void mixColumns(vvector & v)
{
    vvector res(v.begin(), v.end());
    for(int i=0; i<4; i++)
        for(int j=0; j<4; j++)
            v[i][j] = 0x00;

    for(int i=0; i<4; i++)
        for(int j=0; j<4; j++)
            for(int k=0; k<4; k++)
                v[i][j] = v[i][j] ^ gfMultiply(mixBox[i][k], res[k][j]);
}

Theoretically, I understood multiplication gf(2^8), but for implementing algorithm, i have problems. I referred to this site. But either I can not understand some point or I am doing something wrong. In wikipedia I have read this:

“The multiplication operation is defined as: multiplication by 1 means
no change, multiplication by 2 means shifting to the left, and
multiplication by 3 means shifting to the left and then performing xor
with the initial unshifted value. After shifting, a conditional xor
with 0x1B should be performed if the shifted value is larger than
0xFF.”

Assuming above I have implemented this:

short gfMultiply(short h1, short h2)
{
    //h1 can 0x01, 0x02 or 0x03
    short r;
    if(h1==0x01)
        return h2;
    if(h1==0x02)
        r = (h2<<1);
    else
        r = (h2<<1)^h2;
    if(r>0xFF)
        r = r^0x1b;
    return r;
}

But results are incorrect, when I am testing. What I am doing wrong here?

  • 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-04T13:59:36+00:00Added an answer on June 4, 2026 at 1:59 pm

    Sorry, for bug. I have fixed it by myself, this is the correct one:

    short gfMultiply(short h1, short h2)
    {
        //h1 can 0x01, 0x02 or 0x03
        short r;
        if(h1==0x01)
            return h2;
        if(h1==0x02)
        {
            r = (h2<<1);
            if(r>0xFF)
                r = r^0x11b;
        }
        else
        {
            r = (h2<<1);
            if(r>0xFF)
                r = r^0x11b;
            r = r^h2;
        }
        return r;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have committed to learning C now, I'm good with Python/PHP/Bash but I've decided
I'm learning Ruby right now and I got stuck, maybe you guys can help
I'm just learning now the Raphael.js. I have ONE questions: I have an image
I am learning ASP.NET MVC now a days and I have found that most
I have been progressing through Learn Prolog Now! as self-study and am now learning
I'm learning EF now and have a question regarding the ObjectContext: Should I create
I'm now learning a bit of MATLAB and I have two versions of it.
We have a new developer that is just now learning LinqToSql. While going over
I'm just now learning about file tasks in Rake. I have 100s of javascript
I have been in at the deep end for a week now learning from

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.