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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:53:54+00:00 2026-06-12T16:53:54+00:00

Im currently implementing a RC4 decryption and as this algorithm only operates on numbers

  • 0

Im currently implementing a RC4 decryption and as this algorithm only operates on numbers between 0-255, I want to write as safe code as possible and properly use unsigned char variables instead of plain int ones.

Well, this although confronted me with a situation i cannot fortell what will happen.

Given are 3 vars i, j, k:

unsigned char i = 150;
unsigned char j = 155;
unsigned char k = 0;

Will the expression k = (i + j) % 256 properly set k to 49 or to 255 as i+j gets truncated?

Edit: fixed a “j” being spelled as “k”

  • 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-12T16:53:56+00:00Added an answer on June 12, 2026 at 4:53 pm

    The standard guarantees arithmetic on unsigned integer types to be arithmetic modulo 2^N where N is the number of value bits in the type, so the arithmetic will be correct.

    Section 3.9.1 (4) of the n3376 draft of the C++11 standard:

    Unsigned integers, declared unsigned, shall obey the laws of arithmetic modulo 2n where n is the number of bits in the value representation of that particular size of integer.46)

    46)This implies that unsigned arithmetic does not overflow because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting unsigned integer type.

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

Sidebar

Related Questions

i am currently implementing a binary tree in c++ and i want to traverse
I'm currently implementing some code that should, for each method of a class, run
I'm currently implementing a custom MultiPageEditorPart where I want to have multiple pages when
** I am currently implementing fancy URLs to see if these 'solves' this. eg
I am currently implementing an associacion of strings and enums based on this suggestion
I am currently implementing custom events and listeners according to the code posted below.
I'm currently implementing an algorithm that does allot of linear algebra on small matrices
I'm currently implementing a Silverlight application using WCF for the communication between client and
I am currently implementing an algorithm for identifying the axis of minimum inertia of
I am currently implementing Root.plist for the Settings Preferences. I want to make a

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.