首页 > 编程语言 >C#Unicode编码不可逆,Default也不可逆

C#Unicode编码不可逆,Default也不可逆

时间:2023-04-17 18:35:32浏览次数:38  
标签:Console string Encoding C# 可逆 Length Default int byte


不可逆:4个e

unsafe static void Main(string[] args)
 {
 byte[] by = new byte[256];
 for (int i = 0; i < by.Length; i++)
 by[i] = (byte)i;
 string s = Encoding.Unicode.GetString(by);
 byte[] by2 = Encoding.Unicode.GetBytes(s);
 for (int i = 0; i < by.Length; i++)
 {
 if (by[i] != by2[i])
 {
 Console.Write('e');
 }
 }

 Console.ReadKey();
 }
 不 可逆:
 unsafe static void Main(string[] args)
 {
 byte[] by = new byte[256];
 for (int i = 0; i < by.Length; i++)
 by[i] = (byte)(i + 200);
 string s = Encoding.Default.GetString(by);
 byte[] by2 = Encoding.Default.GetBytes(s);
 for (int i = 0; i < by.Length; i++)
 {
 if (by[i] != by2[i])
 {
 Console.Write('e');
 }
 }

 Console.ReadKey();
 }

标签:Console,string,Encoding,C#,可逆,Length,Default,int,byte
From: https://blog.51cto.com/u_16076050/6195825

相关文章

  • 查找消耗cpu最高的Java进程
    #!/bin/bashif[-z"$1"];then###1.先找到消耗cpu最高的Java进程###pid=`ps-eopid,%cpu,cmd--sort=-%cpu|grepjava|grep-vgrep|head-1|awk'END{print$1}'`if["$pid"=""];then......
  • cnoi
    cnoi是黄,群里一堆软色情言论头像。cnoi是赌,比赛全是随机选拔。除非有接近国家队水平。cnoi是毒,退役后有强烈的戒断反应。建议取缔cnoi。 是什么把你变成这样,原神吗?不,是cnoi。cnoi是什么?感觉,不如原神。的确。如果可以选咋,我宁愿去玩原神。 福建省选变成联合省选?不,是联......
  • C#指针读写结构体,效率高
    fixed(int*p1=&point.x){fixed(double*p2=&arr[5]){//Dosomethingwithp1andp2.}}fixed语句禁止垃圾回收器重定位可移动的变量。fixed语句只能出现在不安全的上下文中。Fixed还可用于创建固定大小的缓冲区。fixed语句设置指向托管变量的指针,并在执......
  • C#在文件读写结构体 Marshal效率低
    usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;usingSystem.Runtime.InteropServices;name......
  • elementui select下来内容过长问题解决方案
    :popper-append-to-body="false"必写自定义显示<divclass="select-flow">{{dict.declareConditions}}</div>自定义css样式el-option添加title属性 <el-selectv-model="formData.declCondition"placeholder="请选择"sty......
  • ASP.NET Core MVC 从入门到精通之布局
    随着技术的发展,ASP.NETCoreMVC也推出了好长时间,经过不断的版本更新迭代,已经越来越完善,本系列文章主要讲解ASP.NETCoreMVC开发B/S系统过程中所涉及到的相关内容,适用于初学者,在校毕业生,或其他想从事ASP.NETCoreMVC系统开发的人员。 经过前几篇文章的讲解,初步了解ASP.NETCor......
  • 用reflector看到C#Random类的实现
    [Serializable,ComVisible(true)]publicclassRandom{//Fieldsprivateintinext;privateintinextp;privateconstintMBIG=0x7fffffff;privateconstintMSEED=0x9a4ec86;privateconstintMZ=0;privateint[]SeedArray;//MethodspublicRandom(......
  • docker Ubuntu 安装教程
    启动docker镜像dockerrun-t-i-dubuntu:18.04/bin/bash配置ustc镜像源sed-i's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g'/etc/apt/sources.listsed-i's/security.ubuntu.com/mirrors.ustc.edu.cn/g'/etc/apt/sources.listapt-getcleanap......
  • c# 扩展方法
    由来一个类想要有新的方法,除了简单粗暴的在类中直接添加,当然可以用继承来实现,不过若为扩展一个方法就用继承,这就大材小用了,况且有些类是不能被继承的。于是乎,c#3.0提出了扩展方法,用它来为现有的类型(比如自定义的类)添加方法。如何定义扩展方法a)扩展方法必须在非嵌套(类中类)非......
  • opencv c++ 保存为位深度为1的png
    vector<int>compression_params;compression_params.push_back(IMWRITE_PNG_COMPRESSION);compression_params.push_back(3);compression_params.push_back(IMWRITE_PNG_BILEVEL);compression_params.push_back(1);imwrite("text2.png&......