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

  • Home
  • SEARCH
  • 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 8971325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:55:39+00:00 2026-06-15T17:55:39+00:00

EDIT: this is the corrected version of the converted code int scrambBase20[] = {1,2,3};

  • 0

EDIT: this is the corrected version of the converted code

int scrambBase20[] = {1,2,3};
- (NSString *) descramble:(NSString*) input{
    char *ret = [input UTF8String];
    int offset = -(sizeof scrambBase20);
    for(int i=0;i<[input length];i++){
        if(i%(sizeof scrambBase20)==0){
            offset+=(sizeof scrambBase20);
        }
        ret[scrambBase20[i%(sizeof scrambBase20)]+offset] = (char) ((Byte) [input characterAtIndex:i]^0x45);
    }
    NSString *realRet = [[NSString alloc] initWithUTF8String:ret];
    [realRet stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

    return realRet;
}

I have this block of Java which I am trying to convert to Objective-C.

I have an encrypted string which I am trying to decrypt.

[descramble: @"6&eee *eee1ee1e eee!"];

Should become

"testcode" (without quotes)

Instead, I get the output

"6&sec *ee 1ee1e  ee!" (without quotes)

The following code is my Java code [works]

String descramble(String input){
    Log.i("APP", "input length: " + input.length());
    char[] ret; //= new ArrayList<Character>();
    ret = input.toCharArray();
    int offset = -scrambBase20.length;
    for(int i=0;i<input.length();i++){
        if(i%scrambBase20.length==0)
            offset+=scrambBase20.length;
        ret[scrambBase20[i%scrambBase20.length]+offset]=(char) ((byte) (input.charAt(i))^0x45);
    }

    String realRet = "";
    for (char x : ret){
        realRet+=x;
    }
    realRet = realRet.trim();
    return realRet;
}

The following code is my converted code to Xcode [doesn’t work]

- (NSString *) descramble:(NSString*) input{
   char *ret = [input UTF8String];
   int offset = -(sizeof scrambBase20);
   for(int i=0;i<(sizeof input);i++){
        if(i%(sizeof scrambBase20)==0){
            offset+=(sizeof scrambBase20);
        }
        ret[scrambBase20[i%(sizeof scrambBase20)]+offset] = (char) ((Byte) [input characterAtIndex:i]^0x45);
    }
    NSString *realRet = [[NSString alloc] initWithUTF8String:ret];
    [realRet stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    return realRet;
}

Does anyone see an error in the conversion from Java to Objective-C?

  • 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-15T17:55:40+00:00Added an answer on June 15, 2026 at 5:55 pm

    Since scrambBase20 is an array, you need to use count instead of sizeOf. Objective C equivalent of sizeOf() in Java is count.

    - (NSString *) descramble:(NSString*) input{
       char *ret = [input UTF8String];
       int offset = (-1 * [scrambBase20 count]);
       for(int i=0;i<[input length];i++){
            if(i% [scrambBase20 count] == 0){
                offset+= [scrambBase20 count];
            }
            ret[scrambBase20[i%[scrambBase20 count]+offset] = (char) ((Byte) [input characterAtIndex:i]^0x45);
        }
        NSString *realRet = [[NSString alloc] initWithUTF8String:ret];
        [realRet stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
        return realRet;
    }
    

    For an NSString, equivalent of length() in java to objective c is [string length]. For cString, it is strlen().

    Update:

    As per your edit, it is a C array and not NSArray. In that case you need to use,

    - (NSString *) descramble:(NSString*) input{
        char *ret = [input UTF8String];
        int offset = -1 * ((sizeof scrambBase20) / (sizeof int));
        for(int i=0;i < [input length];i++){
            if(i%((sizeof scrambBase20) / (sizeof int))==0){
                offset+=((sizeof scrambBase20) / (sizeof int));
            }
            ret[scrambBase20[i%((sizeof scrambBase20) / (sizeof int))]+offset] = (char) ((Byte) [input characterAtIndex:i]^0x45);
        }
        NSString *realRet = [[NSString alloc] initWithUTF8String:ret];
        [realRet stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    
        return realRet;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: This code now works correctly, I only left it in case someone finds
My code looks sort of like this, but this is a simplified version: class
I have a line of php code that looks like this: echo <script>$('#edit_errors').html('<h3><em>Please Correct
Edit: This problem was down to me passing the wrong view to the Touch
edit This question is solved! Having something weird. I'm using html { font-size: 100%
Edit: this question is outdated. The jsonlite package flattens automatically. I am dealing with
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
Edit This question has gone through a few iterations by now, so feel free
EDIT: This question is a duplicate of What is the difference between managed and
EDIT: This issue is already submitted on Github. Changing the Act part to this

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.