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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:18:07+00:00 2026-05-17T00:18:07+00:00

String source = WEDGEZ char letter = source.charAt(i); shift=5; for (int i=0;i<source.length();i++){ if (source.charAt(i)

  • 0
String source = "WEDGEZ"
char letter = source.charAt(i);
shift=5;
for (int i=0;i<source.length();i++){
if (source.charAt(i) >=65 && source.charAt(i) <=90 )
  letterMix =(char)(('D' + (letter - 'D' + shift) % 26));
}

Ok what I’m trying to do is take the string WEDGEZ, and shift each letter by 5, so W becomes B and E becomes J, etc. However I feel like there is some inconsistency with the numbers I’m using.

For the if statement, I’m using ASCII values, and for the
letterMix= statement, I’m using the numbers from 1-26 (I think). Well actually, the question is about that too:

What does
(char)(('D' + (letter - 'D' + shift) % 26)); return anyway? It returns a char right, but converted from an int. I found that statement online somewhere I didn’t compose it entirely myself so what exactly does that statement return.

The general problem with this code is that for W it returns ‘/’ and for Z it returns _, which I’m guessing means it’s using the ASCII values. I really dont know how to approach this.

Edit: New code

    for (int i=0;i<source.length();i++)
        {
        char letter = source.charAt(i);
        letterMix=source.charAt(i);
        if (source.charAt(i) >=65 && source.charAt(i) <=90 ){
            letterMix=(char)('A' + (  ( (letter - 'A') + input ) % 26));
            }
        }
  • 1 1 Answer
  • 1 View
  • 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-05-17T00:18:08+00:00Added an answer on May 17, 2026 at 12:18 am

    Well I’m not sure if this homework, so i’ll be stingy with the Code.

    You’re Writing a Caesar Cipher with a shift of 5.

    To address your Z -> _ problem…I’m Assuming you want all the letters to be changed into encoded letters (and not weird Symbols). The problem is ASCII values of A-Z lie between 65 and 90.
    When coding Z (for eg), you end up adding 5 to it, which gives u the value 95 (_).

    What you need to do is Wrap around the available alphabets. First isolate, the relative position of the character in the alphabets (ie A = 0, B = 1 …) You Need to subtract 65 (which is ASCII of A. Add your Shift and then apply modulus 26. This will cause your value to wrap around.

    eg, it your encoding Z, (ASCII=90), so relative position is 25 (= 90 – 65).
    now, 25 + 5 = 30, but you need the value to be within 26. so you take modulus 26
    so 30 % 26 is 4 which is E.

    So here it is

    char letter = message(i);
    int relativePosition = letter - 'A'; // 0-25
    int encode = (relativePosition + shift) % 26
    char encodedChar = encode + 'A' // convert it back to ASCII.
    

    So in one line,

    char encodedChar = 'A' + (  ( (letter - 'A') + shift ) % 26)
    

    Note, This will work only for upper case, if your planning to use lower case, you’ll need some extra processing.

    You can use Character.isUpperCase() to check for upper case.

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

Sidebar

Related Questions

Given the following code: string source = Some Unicode String; foreach( char value in
I have some API instructions I am trying to follow (string) source (string) key
In my header file, I have this: std::string StringExtend(const std::string Source, const unsigned int
There is a method Regex.Replace(string source, string pattern, string replacement) The last parameter supports
How to convert link to source ( string containing the URL ) to stream
If we have a source string and encrypted string, can we find out algorithm/forumla
I am working on string maniplations using regex. Source: string value = @/webdav/MyPublication/Building%20Blocks/folder0/folder1/content_1.xml; output
How to do this using standard methods (without manual iteration through source string)? PS:
I am using the following code to fetch html source website. private string Extract_Source(string
I have a string read from another source such as \b\bfoo\bx. In this case,

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.