zoukankan
html css js c++ java
加码解码
public
string
EncodingSMS(
string
s)
{
string
result
=
string
.Empty;
byte
[] arrByte
=
System.Text.Encoding.GetEncoding(
"
GB2312
"
).GetBytes(s);
for
(
int
i
=
0
; i
<
arrByte.Length; i
++
)
{
result
+=
System.Convert.ToString(arrByte[i],
16
);
//
Convert.ToString(byte, 16)把byte转化成十六进制string
}
return
result;
}
public
string
DecodingSMS(
string
s)
{
string
result
=
string
.Empty;
byte
[] arrByte
=
new
byte
[s.Length / 2
];
int
index
=
0
;
for
(
int
i
=
0
; i
<
s.Length; i
+=
2
)
{
arrByte[index
++
]
=
Convert.ToByte(s.Substring(i,
2
),
16
);
//
Convert.ToByte(string,16)把十六进制string转化成byte
}
result
=
System.Text.Encoding.Default.GetString(arrByte);
return
result;
}
加码解码的规则如下:
加码时将字符串中的所有字符转换成其对应的ASCII值的16进制值,例如:“A”的ASCII码值为65,以16进制值表示为41,故应发送两个字符“41”以代表字符“A”。
对于汉字则以其内码的16进制值来表示,如“测试”应为:B2E2CAD4。
原理:
string
aaa
=
"
AB测试
"
;
byte
[] bbb
=
System.Text.Encoding.Default.GetBytes(aaa);
string
ccc
=
System.Text.Encoding.Default.GetString(bbb);
for
(
int
i
=
0
; i
<
bbb.Length; i
++
)
{
Response.Write(System.Convert.ToString(bbb[i],
16
));
}
Response.Write(ccc);
查看全文
相关阅读:
杂记5
杂记4
杂记3
杂记2
杂记1
也来个网页版本的五子棋
验证码识别
npm publish命令
window nginx php ci框架环境搭建
也来个网页版本的五子棋
原文地址:https://www.cnblogs.com/xiaodi/p/145493.html
最新文章
详解在Visual Studio中使用git版本系统(图文)
git extensions远程配置
C#中 protected internal 和 internal 的区别
Python 自动登录网站(处理Cookie)
python gdal 修改shp文件的属性值
python gdal 数组生成图片
python 根据数组生成图片
python gdal 矢量转栅格
ie9以下的浏览器兼容性问题
window.showModalDialog的问题
热门文章
将子节点的所有父节点ID合并成一个字符串,并更新表
sqlplus运行sql文件
当表中数据不存在即插入,当存在时,即更新
echarts3 -arcgis echarts.js修改
东拼西凑的模板·持续更新中
杂记10
杂记9
杂记8
杂记7
杂记6
Copyright © 2011-2022 走看看