加密解密 C# Delphi 兼容互转
来源:互联网 发布:网络直播是什么 编辑:程序博客网 时间:2024/05/17 23:13
C#:
//解密
public static string HStrToStr(String sInfo)
{
string sResult = "";
if (String.IsNullOrEmpty(sInfo))
{
return sResult = "";
}
int iValue = 0; byte rValue = 0;
int iResultLen=(sInfo.Length >> 1);
//随机密匙取出来
rValue = (byte)(sInfo[sInfo.Length - 1]);
for (int i = 0; i < iResultLen; i++)
{
//奇数数列
int iOS = (i + 1) * 2 - 1;
int iJS = (i) * 2;
char cValue = (char)((((byte)(sInfo[iJS]) - 80) << 4) + ((byte)(sInfo[iOS]) - 89));
cValue = (char)((byte)(cValue) ^ ((i+1) & 0xFF));
cValue = (char)((byte)(cValue) ^ rValue);
sResult += "" + cValue;
}
return sResult;
}
//加密
public static string StrToHStr(String sInfo)
{
string sResult = "";
if (String.IsNullOrEmpty(sInfo))
{
return sResult = "";
}
int iValue = 0; byte rValue = 0;
char[] sDeal = new char[sInfo.Length];
Random rnd = new Random();
rValue = (byte)(rnd.Next(60) + 35);
for (int i = 0; i < sInfo.Length; i++)
{
sDeal[i]=(char)((byte)sInfo[i] ^ rValue);
sDeal[i] = (char)(((byte)sDeal[i]) ^ ((i + 1) & 0xFF));
sResult += "" +(char)((((byte)(sDeal[i]) & 0xF0) >> 4) + 80) +(char)((((byte)(sDeal[i]) & 0x0F)) + 89);
}
//随机密匙放在最后一位。
sResult += "" + (char)rValue;
return sResult;
}
Delphi:
function strtohstr(s: string): string;
var
i: integer;
r: byte;
begin
Randomize;
r := Random(60) + 35;
result := '';
for i := 1 to length(s) do
begin
s[i] := chr(ord(s[i]) xor r);
s[i] := chr(ord(s[i]) xor (i and $FF));
result := result + chr(((ord(s[i]) and $F0) shr 4) + 80) + chr(((ord(s[i]) and $F)) + 89);
end;
result := result + chr(r);
end;
//字符解密
function hstrtostr(s: string): string;
var i: integer;
c: char;
r: byte;
begin
result := '';
if s = '' then exit;
r := ord(s[length(s)]);
for i := 1 to length(s) shr 1 do
begin
c := chr(((ord(s[i * 2 - 1]) - 80) shl 4) + (ord(s[i * 2]) - 89));
c := chr(ord(c) xor (i and $FF));
c := chr(ord(c) xor r);
result := result + c;
end;
end;
阅读全文
0 0
- 加密解密 Delphi C# 兼容互转
- 加密解密 Delphi C# 兼容互转
- 加密解密 C# Delphi 兼容互转
- delphi加密C#解密示例源码说明
- java delphi aes 加密与解密文件兼容算法
- DES ECB模式JAVA PHP C#实现加密、解密兼容
- 【转】QQ Tea加密解密单元 Delphi
- [转]C#加密解密源码
- C#加密解密方法(转)
- C#加密与解密 (转)
- Delphi 加密解密
- delphi 加密解密函数
- Delphi字符串加密解密
- Delphi加密解密算法
- 加密和解密(delphi实现)
- Delphi字符串加密解密函数
- Delphi字符串加密解密函数
- Delphi DES加密解密单元
- git 命令之暂存相关指令。
- java------重写,重载
- 完美的分页及模板引掣案例
- git命令总结(一)
- 春运购票捡漏
- 加密解密 C# Delphi 兼容互转
- CSS规则
- 想邻数字的基数等比:确定进制
- 全球科技巨擘大战AI
- Hive over HBase和Hive over HDFS性能比较分析
- 启动tomcat的小错误报告
- 【Scikit-Learn 中文文档】神经网络模型(无监督)- 无监督学习
- DG实施文档及遇到问题处理方法
- oninput、onchange与onpropertychange事件的用法和区别