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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:45:33+00:00 2026-05-19T15:45:33+00:00

I’ve been working on converting a C++ crypting method to C#. The problem is,

  • 0

I’ve been working on converting a C++ crypting method to C#. The problem is, I cant get it to encrypt/decrypt the way I want it to.

The idea is simple, I capture a packet, and decrypt it. The output will be:
Packet Size – Command/Action – Null (End)

(The decryptor cuts off the first and last 2 bytes)

The C++ code is this:

// Crypt the packet with Xor operator
void cryptPacket(char *packet)
{
    unsigned short paksize=(*((unsigned short*)&packet[0])) - 2;

    for(int i=2; i<paksize; i++)
    {
         packet[i] = 0x61 ^ packet[i];
    }
}

So I thought this would work in C# if I didn’t want to use pointers:

public static char[] CryptPacket(char[] packet)
{
    ushort paksize = (ushort) (packet.Length - 2);

    for(int i=2; i<paksize; i++)
    {
        packet[i] = (char) (0x61 ^ packet[i]);
    }

    return packet;
}

-but it isn’t, the value returned is just another line of rubish instead of the decrypted value. The output given is: ..O♦&/OOOe.

Well.. atleast the ‘/’ is in the right place for some reason.

Some more information:

  • The test packet I’m using is this:

Hex value: 0C 00 E2 66 65 47 4E 09 04 13 65 00

Plain text: …feGN…e.

Decrypted: XX/hereXX

X = Unknown value, I cant really remember, but it doesn’t matter.

  • Using Hex Workshop you can decrypt the packet this way:
    1. Special Paste the hex value as CF_TEXT, make sure the ‘treat as hexidecimal value’ box is checked.
    2. Afterwards, select everything from the hexidecimal value you just pasted, except the first and last 2 bytes.
    3. Go to Tools>Operations>Xor.
    4. Select ‘Treat data as 8 bit data’ and set value to ’61’.
    5. Press ‘OK’, and you’r done.

That’s all the information I can give at the moment, because I’m writing this off the top of my head.

Thank you for your time.

In case you don’t see a question in this:

It would be great if someone could take a look at the code to see what’s wrong with it, or if there’s another way to do it. I’m converting this code because I’m horrible with C++, and want to create a C# application with that code.

Ps: The code tags and such were a pain, so I’m sorry if the spacing etc. is a little messed up.

  • 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-05-19T15:45:33+00:00Added an answer on May 19, 2026 at 3:45 pm

    I just tried your function and it seems ok:

    class Program
    {
        // OP's method: http://stackoverflow.com/questions/4815959
        public static byte[] CryptPacket(byte[] packet)
        {
            int paksize = packet.Length - 2;
            for (int i = 2; i < paksize; i++)
            {
                packet[i] = (byte)(0x61 ^ packet[i]);
            }
            return packet;
        }
    
        // http://stackoverflow.com/questions/321370 :)
        public static byte[] StringToByteArray(string hex)
        {
            return Enumerable.Range(0, hex.Length).
                   Where(x => 0 == x % 2).
                   Select(x => Convert.ToByte(hex.Substring(x, 2), 16)).
                   ToArray();
        }
    
        static void Main(string[] args)
        {
            string hex = "0C 00 E2 66 65 47 4E 09 04 13 65 00".Replace(" ", "");
            byte[] input = StringToByteArray(hex);
            Console.WriteLine("Input: " + ASCIIEncoding.ASCII.GetString(input));
            byte[] output = CryptPacket(input);
            Console.WriteLine("Output: " + ASCIIEncoding.ASCII.GetString(output));
            Console.ReadLine();
        }
    }
    

    Console output:

    Input: ...feGN.....
    Output: ...../here..
    (where '.' represents funny ascii characters)
    

    It seems a bit smelly that your CryptPacket method is overwriting the initial array with the output values. And that irrelevant characters are not trimmed. But if you are trying to port something, I guess you should know what you are doing.

    You could also consider trimming the input array, to remove the unwanted characters first, and then use a generic ROT13 method (like this one). This way you have your own “specialized” version with 2-byte offsets inside the crypt function itself, instead of something like:

    public static byte[] CryptPacket(byte[] packet)
    {
        // create a new instance
        byte[] output = new byte[packet.Length];
    
        // process ALL array items
        for (int i = 0; i < packet.Length; i++)
        {
            output[i] = (byte)(0x61 ^ packet[i]);
        }
    
        return output;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.