Question : C#  equation to Compress string

Hi
I have 35 Character String that I need to convert to 25 Character String
And From 25 Character String i can Return back to 35 Character String
So there is any Math equation can I used to implement this
Im using C# applications

Answer : C#  equation to Compress string

I made a solution for you. I noticed that it can't be a hex because you have such chars like 'M' and 'G'. Looks like you are using '0' to '9' + 'A' to 'Z' as your source.
It's a pity that I can't reach out an output with readable strings. But the cipher length is exactly 18 chars just as you want.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
        Int16 Char2Int(char value)
        {
            if(value>='0' && value<='9')
                return (Int16)(value-'0');
            return (Int16)(char.ToUpper(value) - 'A' + 10);
        }
        char Int2Char(Int16 value)
        {
            if (value < 10)
                return (char)('0' + value);
            return (char)('A' + value - 10);
        }

        public string Encode(string plain)
        {
            plain = "0"+plain.Replace("-", ""); // remove the '-'
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < plain.Length; i+=2)
            {
                char value = (char)((Char2Int(plain[i]) << 8) + Char2Int(plain[i + 1]));
                Int16 v1 = (Int16)(value & 0xff);
                Int16 v2 = (Int16)((value & 0xff00) >> 8);
                sb.Append(value);
            }
            return sb.ToString();
        }

        public string Decode(string cipher)
        {
            StringBuilder sb = new StringBuilder();
            foreach (char ch in cipher)
            {
                Int16 v1 = (Int16)((ch & 0xff00) >> 8);
                Int16 v2 = (Int16)(ch & 0xff);
                sb.Append(Int2Char(v1));
                sb.Append(Int2Char(v2));
            }
            return sb.ToString().Substring(1, 35);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str = "FFF80-0EIBB-0CF0F-E6MFG-0A0BB-30221-22009";
            string cipher = Encode(str);
            string plain = Decode(cipher);
            return;
        }
Random Solutions  
 
programming4us programming4us