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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:40:57+00:00 2026-06-13T11:40:57+00:00

I am trying to convert a JavaScript hashing function to C# hashing to do

  • 0

I am trying to convert a JavaScript hashing function to C# hashing to do the exact same thing. I’m 99% there but I hit a snag with decimals used in this custom function.
Am not sure why but this function convert a hashed value to a decimal for some odd reason and my problem is that decimals generated are not always the same length. The decimals in C# are quite a bit longer but are uniform length. The problem i am having is because rounding in C# works differently than JavaScript I don’t know exactly at what decimal to round to create the equivalent length string.

Here is an example of two generated decimal strings that are appended to each other. Both start from 4,4 and 3 character strings:

4 char string generates 79957.88183577501
4 char string generates 160933.02806113224
3 char string generates 609.9111294990053

Using the exact same code C# generates using the exact same inputs:

79957.88183577500452161331162
160933.02806113221197323204919
609.91112949900524507144149035

If all strings were the same length it would not be a problem but I have no idea how to determine when JS will generate the longer decimal. Any clues? Comments? Opinions?

Unfortunately the receiving code is still the original JS which simply reverses the process hence I have to duplicate the end result perfectly for all inputs.

EDIT:

Here is the problematic section. Don’t ask me why it works like that, I didn’t write it.

// oString is a full string to be encoded
// oKey is a key to be used for encoding
function completeHash(oString,oKey) {
    if( oKey.length < 5 ) {
        window.alert( 'The key must be at least 5 characters long' );
        return oString;
    }
    var oKeyNum = new Array(), oOutStr = '', oOp = new Array('+=','/=','-=','*= 0.01 *');
    for (var x = 0; x < oKey.length; x++) {
        oKeyNum[x] = parseInt('0x' + completeEscape(oKey.charAt(x)));
    }

    for( var x = 0, y = ''; x < oString.length; x += Math.round( oKey.length / 2 ), y = 'O.O' ) {
        var theNum = parseInt( '0x' + completeEscape( oString.substr( x, Math.round( oKey.length / 2 ) ) ) );

        // next two lines are problematic with decimals not having equal length
        for( var z = 0; z < oKey.length; z++ ) {
            eval( 'theNum ' + oOp[z % 4] + ' ' + oKeyNum[z] + ';' );
            alert('theNum:' + theNum);
        }

        oOutStr += y + theNum;
    }
    return oOutStr;
}

completeEscape() function simply returns ASCII int codes for each character.

I got the whole thing working nicely except the length of the decimals.

  • 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-13T11:40:59+00:00Added an answer on June 13, 2026 at 11:40 am

    If you’re using Number in javascript, then use double in C#. Both are 64-bit IEEE 754 numbers (double-precision). You get the same values (updated after verifying this).

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

Sidebar

Related Questions

I'm trying to convert a function from Javascript to CoffeeScript. This is the code:
I'm trying to convert this Javascript code: self.userSerialEvent = function (join, value, tokens) {
Im trying to convert this php function to javascript: function sanitize_words($string,$limit=false) { preg_match_all(/\p{L}[\p{L}\p{Mn}\p{Pd}'\x{2019}]{1,}/u,$string,$matches,PREG_PATTERN_ORDER); return
I'm trying to convert the following jquery to javascript syntax, but being not familiar
I'm trying to convert some code from Javascript to c. The function creates an
I am trying to convert this piece of html code to javascript so that
I'm trying to convert a preexisting javascript function into a jQuery function. The function
i'm quite new to Dojo, but i am trying to convert an existing javascript
I've been trying to convert this JavaScript code that gets the dominant color from
I'm trying to convert this code from Javascript to CoffeeScript: for (var i =

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.