字符串编码程序

本文关键字:程序 编码 字符串 | 更新日期: 2023-09-27 18:27:06

测试用例:

banagalore (of type String)

预期输出:

{30,20,21,92,20,80,32,31,02}

我已经用C#将它们转换为ASCII,现在我无法将它们转换成那个序列,请提出一些想法。

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            Console.WriteLine("Enter The String ");
            string str = Console.ReadLine();
            byte[] b = Encoding.ASCII.GetBytes(str);
            foreach (var item in b)
            {
                Console.WriteLine(item);
            }
        }
    }
}

字符串编码程序

XOR掩码是一种选择。

byte[] input = Encoding.ASCII.GetBytes("bangalore");
var known_result = new byte[] { 30, 20, 21, 92, 20, 80, 32, 31, 02 };
var computed_mask = new byte[input.Length];
for (var i = 0; i < input.Length; i++)
{
    computed_mask[i] = (byte)(known_result[i] ^ input[i]);
}
byte[] test = Encoding.ASCII.GetBytes("bangalore");
for (var i = 0; i < test.Length; i++)
{
    test[i] ^= computed_mask[i];
}
Console.WriteLine(string.Join(",", test));