Code Series --Base24 Coding

xiaoxiao2021-03-06  57

0, write in front

The serial number of Windows and Office is after the final conversion, converted through the base24 encoded to display a string. The purpose of writing this series is to do something similar.

1, coding principle

In the article of Base32, it has been more detailed. Here is only compared with the principle, base24 is a very strange solution because four BITs can be used as a divided segment, only 16, and 8 other The coding character is not used, and 5 BITS is used as a division section, and there are fewer characters. This is the reason for the previously written Base32.

Later, I wanted to understand this problem, or a group of 4 bits, and then used 24 characters in another way, I used a more stupid way, according to the remainder of 8, plus The encoded value is converted. In short, there is no difference.

First, I don't know what the specific way of the base24 used by MS is, because it is different from what I described, because it is said that it is 200 BITS (25 BYtes)

I said that the method I said clearly. I am now going to this point, I think about it.

2, source code

The two functions of Encoding and Decoding are only laid out, and the other is similar.

Public new static string encode (byte [] abdata) {INT32 dwloop = 0, dwcharndex = 0, dwcharcount = 0, dwrem = 0; char [] acpart = null; stringbuilder sboutput = null;

IF (abdata == null || m_acbasemap == null || m_acbasemap.LENGTH

try {dwCharCount = abData.Length * 2; sbOutput = new StringBuilder (dwCharCount); acPart = new Char [2];} catch (Exception e) {Trace.WriteLine ( "CLsBase24.Encode:! Initialize buffer failed" e. Message);} if (acpart == null || sboutput == null) Return NULL;

For (dwloop > 4) dwrem; acpart [0] = m_acbasemap [dwcharindex]; dwcharindex = (abdata [dwloop] & 0x0f) dwrem; acpart [1] = m_acbasemap [dwcharindex]; sboutput.Append ( Acpart, 0, acpart.length;}

Return Sboutput.toString ();

Public new static byte [] decode (string sdata) {INT32 dwloop = 0, dwlength = 0, dwLength = 0; int32 [] dwcharindex = null; byte [] Aboutput = null; char [] acinput = null; if (sdata = = NULL || SDATA == String.empty) Return NULL;

Acinput = SDATA.TOCHARARRAY (); if (acinput == null) Return NULL;

Try {dwLength = acinput.length / 2; Aboutput = new byte [dwLength]; dwcharindex = new int32 [2];} catch (exception e) {trace.writeline ("CLSBase24.Decode: Initialize Buffer Faied!" E. IF (acinput == null) Return NULL;

DWLENGTH = 0; for (dwloop = 0; dwloop

Default: dwcharindex [0] = getcharindex (acinput [dwloop]) - dwrem; dwcharindex [1] = getCharindex (acinput [dwloop 1]) - dwrem; Aboutput [dwlength] = (Byte) ((DWcharIndex [0] << 4) DWCHARINDEX [1]); Break;

DWLENGTH ;}

Return ABOUT;

转载请注明原文地址:https://www.9cbs.com/read-113938.html

New Post(0)