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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:23:26+00:00 2026-06-08T17:23:26+00:00

More specifically, I put a breakpoint in my code after NSString *signStr = [NSString

  • 0

More specifically, I put a breakpoint in my code after
NSString *signStr = [NSString stringWithCString:text encoding:NSASCIIStringEncoding];
I am calling the function with secret= @"12345678901234567890" and movingFactor = 1
I noticed that at the breakpoint, signStr is an empty string,
also are there any other noticeable errors in the code?
Thanks

-(NSString*) generateOTP:(NSString*) secret with:(uint64_t) movingFactor
{
    NSString* result;

    const int DIGITS = 6;
    const int SIX_DIGITS = 1000000;

    char text[8];
    for (int i = 7; i >= 0; i--) {
        text[i] = movingFactor & 0xff;
        movingFactor >>= 8;
    }

    NSString *signStr = [NSString stringWithCString:text encoding:NSASCIIStringEncoding];

    NSString* hash = [self sha1UseKey:secret toSign:signStr];

    int offset = [hash characterAtIndex:[hash length] - 1] & 0xf;

    int binary = (([hash characterAtIndex:offset] & 0x7f) << 24) |
        (([hash characterAtIndex:offset+1] & 0xff) << 16) |
        (([hash characterAtIndex:offset+2] & 0xff) << 8) | ([hash characterAtIndex:offset+3] & 0xff);

    int otp = binary % SIX_DIGITS;

    result = [NSString stringWithFormat:@"%d", otp];

    NSString* zero = @"0";
    while ([result length] < DIGITS) {
        result = [zero stringByAppendingString:result];
    }
    return result;

}
  • 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-08T17:23:27+00:00Added an answer on June 8, 2026 at 5:23 pm

    To be a “C string” it has to be terminated by a zero ('\0'). If movingFactor is 1 then the last character will be 0x01, and the first (and every other byte) is zero due to shifting. This makes the first character zero, which makes the string “empty”.

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

Sidebar

Related Questions

When using the PHP Tidy Library (More Specifically, The tidy_repair_string function) I keep getting
Editing a RichTextBox control's text (more specifically, modifying selection font/color) programmatically seems to be
Is there any way to put conditions in MSBuild-extension? More specifically, I need to
More specifically I want to test whether Oracle ODP.Net is installed on a machine.
More specifically, is List(T)(IEnumerable(T)) thread-safe if the IEnumerable used to initialize the list is
More specifically, does NDK have a complete STL implementation. We're looking at this for
More specifically, I was using homebrew to install MySQL, and I got this error:
...or more specifically, how are they able to create animations via javascript, which is
I am making a GUI in OpenGL (more specifically lwjgl). I have tried hard
http://developer.yahoo.com/yui/button More specifically, I want radio buttons. that can be checked/unchecked.

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.