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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:47:19+00:00 2026-06-03T14:47:19+00:00

I have a problem with normal DES encryption in C#, I want an output

  • 0

I have a problem with normal DES encryption in C#, I want an output string with 16 char length (16 bytes 128 bit) that it contains only alphabetic and numeric characters.

  • 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-03T14:47:20+00:00Added an answer on June 3, 2026 at 2:47 pm

    If you are limited to 16-character output consisting only of alphanumeric characters, it means you have ~95 bits of output space available (exactly 96 bits if you could use Base-64 encoding, i.e. include 2 non-alphanumeric characters).

    Therefore, nothing you could do would allow you to encrypt more than 95 bits with this restriction. If this is sufficient for you, it is possible.

    Something like this (3DES in CTR mode) is an example how it could work (using Base-64), but as stated above in the comments, it really depends on what you really are trying to do.

    void Main()
    {
        var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
        var key = new byte[] { 01, 12, 23, 34, 45, 56, 67, 78, 89, 90, 09, 98, 87, 76, 65, 54, 43, 32, 21, 10, 11, 22, 33, 44 };
        var encrypted = Encrypt(data, key, 0);
        Console.WriteLine(encrypted);
        var decrypted = Decrypt(encrypted, key, 0);
        // decrypted should be equal to data here
    }
    
    public string Encrypt(byte[] data, byte[] key, long nonce)
    {
        return Convert.ToBase64String(Transform(data, key, nonce));
    }
    
    public byte[] Decrypt(string data, byte[] key, long nonce)
    {
        return Transform(Convert.FromBase64String(data), key, nonce);
    }
    
    byte[] Transform(byte[] data, byte[] key, long nonce)
    {
        if (data.Length > 96/8) throw new ArgumentException("Too much data");
    
        using (var des = new TripleDESCryptoServiceProvider())
        {
            des.Key = key;
            des.Mode = CipherMode.ECB;
            using (var encryptor = des.CreateEncryptor())
            {
                var output = new byte[data.Length];
                var offset = 0;
                for(int counter = 0; counter <= data.Length / 8; ++counter)
                {
                    var counterData = BitConverter.GetBytes(((long)counter) ^ nonce);
                    var counterEncryption = new byte[des.BlockSize / 8];
                    var counterEncryptionLen = encryptor.TransformBlock(counterData, 0, counterData.Length, counterEncryption, 0);
                    Debug.Assert(counterEncryptionLen == counterEncryption.Length);
                    for (var i = 0; i < des.BlockSize / 8 && offset < output.Length; ++i, ++offset)
                    {
                        output[offset] = (byte)(data[offset] ^ counterEncryption[i]);
                    }
                }
                return output;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with fancybox. I want to write a function that will run
My problem is normal issue that may be faced by every developer. I have
I have a problem with my activity. This is my onCreate: case NORMAL: game
I have a peculiar problem. I created a normal Objective C class called SampleTable.
I have problem with HTTP headers, they're encoded in ASCII and I want to
I have a problem with the normal way rails operates when using nested forms
I have a normal map in my OpenGL game engine and I realized that
I have a problem with MFC dialog boxes that are drawn using derived MFC
I have a problem with X11. I created a normal Window and when I
I have problem with deserialization of json string, because string is bad format. For

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.