Node Server Running on Ubuntu that needs to execute a C# application - how?

General Tech Bugs & Fixes 2 years ago

1 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 28 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I have a very simple C# application that was written by a previous person. It uses the MD5CryptoServiceProvider to compute hash using some seed strings to generate a random code.

I have a Node.js server running that I'd like to execute this app and consume the output.

I cannot figure out how to run C# from Ubuntu and I cannot find an MD5 library that comes up with the same answer.

Here is the entirety of the function:

{

  MD5 md5 = new MD5CryptoServiceProvider();

  byte[] encodeBytes = System.Text.Encoding.UTF8.GetBytes(seed1+ seed2+ seed3);

  byte[] output = md5.ComputeHash(encodeBytes);

  string result = string.Format("{0:D}{1:D}{2:D}{3:D}{4:D}{5:D}",

                                ((output[0] + output[1]) % 10), ((output[2] + output[3] + output[4]) % 10),

                                ((output[5] + output[6]) % 10), ((output[7] + output[8] + output[9]) % 10),

                                ((output[10] + output[11] + output[12]) % 10), ((output[13] + output[14] + output[15]) % 10));

  return result;

}

Is it possible for me to modify this C# script to run as a child process or get the same answer using a C++ script, which I have gotten to run with a Node server previously.

Thank you!!

profilepic.png
manpreet 2 years ago

You should just convert your code to Javascript:

function generateCode() {

  let seed1 = 'abc';
  let seed2 = 'def';
  let seed3 = 'ghi';
  let hashed = md5(seed1 + seed2 + seed3);
  let values = [];

  for (let i = 0; i < hashed.length; i += 2) {
    values.push(parseInt('0x' + hashed.substr(i, 2)));
  }

  let codeParts = [((values[0] + values[1]) % 10), ((values[2] + values[3] + values[4]) % 10),((values[5] + values[6]) % 10), ((values[7] + values[8] + values[9]) % 10),((values[10] + values[11] + values[12]) % 10), ((values[13] + values[14] + values[15]) % 10)];
  let code = codeParts.join('');
    alert(code);
}

generateCode();

1 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community