1 Star 0 Fork 0

Feeng / crpt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Program.cs 2.59 KB
一键复制 编辑 原始数据 按行查看 历史
Feeng 提交于 2013-08-22 00:33 . Update key.
using System;
using System.Collections.Generic;
using System.Diagnostics;
//using System.Linq;
using System.Security.Cryptography;
using System.Text;
//using System.Threading.Tasks;
namespace crpt
{
class Program
{
private static char[] codeTab = new char[256];
private static void InitCodeTab()
{
for (int i = 97; i <= 122; i++)
{
char upper = (char)(i - 97 + 65);
codeTab[i] = upper;
codeTab[upper] = upper;
}
for (int i = 48; i <= 57; i++)
{
codeTab[i] = (char)i;
}
codeTab[32] = ' ';
codeTab[44] = ',';
codeTab[46] = '.';
}
private static String toStrTab(String s)
{
char lastCh = '\0';
StringBuilder sb = new StringBuilder(s.Length);
int length = s.Length;
for (int i = 0; i < length; i++)
{
char ch = s[i];
if (ch < 'Ā')
{
ch = codeTab[ch];
if ((ch == 0) || ((lastCh == ' ') && (ch == ' ')))
continue;
lastCh = ch;
sb.Append(ch);
}
}
return sb.ToString().Trim();
}
static void Main(string[] args)
{
string str = args[0];
InitCodeTab();
//string str = "200001|pdsb|20121017105425|2012101700000078|pdsb0001|pdsb_pds|01|3042060759||20121017|";
str = toStrTab(str);
byte[] hash;
using (MD5 md5 = MD5.Create())
{
hash = md5.ComputeHash(Encoding.Default.GetBytes(str));
}
byte[] dest = new byte[8];
for (int i = 0; i < 8; i++)
{
dest[i] = (byte)(hash[i] ^ hash[8 + i]);
}
byte[] key = new byte[8];
//7B 2F EF C3 04 C2 BC 9D
key[0] = 0x7b;
key[1] = 0x2f;
key[2] = 0xef;
key[3] = 0xc3;
key[4] = 0x04;
key[5] = 0xc2;
key[6] = 0xbc;
key[7] = 0x9d;
var des = DES.Create();
des.Mode = CipherMode.ECB;
des.Padding = PaddingMode.None;
des.Key = key;
var encryptor1 = des.CreateEncryptor();
byte[] outBlock = encryptor1.TransformFinalBlock(dest, 0, dest.Length);
Console.Write(BitConverter.ToString(outBlock).Replace("-", string.Empty));
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/Feeng/crpt.git
git@gitee.com:Feeng/crpt.git
Feeng
crpt
crpt
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891