本来想把PB 的函数封装成COM组件调用,结果怎么都搞不定,只能讲代码搞出来换种语言实现了.

string s_ret
integer i_first,i_second,i_third,i_fourth
integer by4,i,reallen
long i_total
string is_key
string is_base64
string EncMap[ to ]
int DecMap[ to ]
integer by3
long i_len is_base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
is_base64 = is_base64 + "abcdefghijklmnopqrstuvwxyz"
is_base64 = is_base64 + ""
is_base64 = is_base64 + "+/"
for i = to
EncMap[i]=mid(is_base64,i+,)
next
for i = to
DecMap[asc(EncMap[i])] = i
next
choose case a_type
case //加密
s_ret = ""
if len(a_text)= then
return s_ret
end if
by3=len(a_text) - mod(len(a_text),)
i=
do while i<= by3
i_first = asc(mid(a_text,i + ,))
i_second = asc(mid(a_text, i + ,))
i_third = asc(mid(a_text,i + ,))
s_ret = s_ret + encmap[i_first / ]
s_ret = s_ret + encmap[mod(i_first , ) * + i_second / ]
s_ret = s_ret + encmap[mod(i_second , ) * + i_third / ]
s_ret = s_ret + encmap[mod(i_third , )]
i = i +
loop
if i <= len(a_text) then
i_first = asc(mid(a_text, i + , ))
if mod(len(a_text), )= then
i_second =asc(mid(a_text,i+,))
s_ret = s_ret + encmap[i_first / ]
s_ret = s_ret + encmap[mod(i_first , ) * + i_second / ]
s_ret = s_ret + encmap[mod(i_second , ) * ]
s_ret = s_ret + "="
else
s_ret = s_ret + encmap[i_first / ]
s_ret = s_ret + encmap[mod(i_first,) * ]
s_ret = s_ret + "=="
end if
end if
i_len = len(s_ret)
s_ret = left(string(i_len+),) + s_ret case //解密
if len(a_text)= then
s_ret = ""
return s_ret
end if
a_text=right(a_text,len(a_text)-)
reallen = len(a_text)
do while mid(a_text,reallen,) = "="
reallen = reallen -
loop
by4=reallen - mod(reallen,)
i=
do while i<= by4
i_first = decmap[asc(mid(a_text,i + ,))]
i_second = decmap[asc(mid(a_text, i + ,))]
i_third = decmap[asc(mid(a_text,i + ,))]
i_fourth = decmap[asc(mid(a_text,i + ,))]
s_ret = s_ret + char(i_first * + i_second / )
s_ret = s_ret + char(mod(i_second,) * + i_third / )
if mod(i_third,) * + i_fourth <> then
s_ret = s_ret + char(mod(i_third,) * + i_fourth)
end if
i = i +
loop
if i<= reallen then //只可能是xx==或xxx=两种形式有效
if mod(reallen,) = then //xx==形式
i_first = decmap[asc(mid(a_text,i + ,))]
i_second = decmap[asc(mid(a_text, i + ,))]
s_ret = s_ret + char(i_first * + i_second / )
s_ret = s_ret + char(mod(i_second,) * )
else
i_first = decmap[asc(mid(a_text,i + ,))]
i_second = decmap[asc(mid(a_text, i + ,))]
i_third = decmap[asc(mid(a_text,i + ,))]
s_ret = s_ret + char(i_first * + i_second / )
s_ret = s_ret + char(mod(i_second,) * + i_third / )
end if
end if end choose
return s_ret
        public static string right(string s1, int str)
{
return s1.Substring(s1.Trim().Length - str, str);
} public static string left(string s1, int str)
{
return s1.Substring( , str);
} public static char mid(string s1, int str, int len)
{
return s1.Substring(str, len).ToArray()[];
} public static int asc(char c1)
{
return(int)c1;
} public static int mod(int x,int y)
{
return x % y;
} public static int len(string s1)
{
return s1.Length;
} public static string encrypt(string a_text, string type = "")
{
string s_ret;
int i_first, i_second, i_third, i_fourth;
int by4, i, reallen;
long i_total;
string is_key;
string is_base64;
char[] encmap = new char[];
int[] decmap = new int[];
int by3 = ;
long i_len; is_base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
is_base64 = is_base64 + "abcdefghijklmnopqrstuvwxyz";
is_base64 = is_base64 + "";
is_base64 = is_base64 + "+/"; char[] tk = is_base64.ToCharArray(); for (i = ; i <= ; i++)
{
encmap[i] = tk[i];
} for (i = ; i <= ; i++)
{
int tp = (int)asc(encmap[i]);
decmap[tp] = i;
} s_ret = "";
if (a_text.Trim() == "")
{
return s_ret;
} if (type == "")
{
by3 = a_text.Length - (a_text.Length % ); i = ;
while (i < by3)
{
i_first = asc(mid(a_text, i + , )); i_second = asc(mid(a_text, i + , ));
i_third = asc(mid(a_text, i + , ));
s_ret = s_ret + encmap[i_first / ];
s_ret = s_ret + encmap[mod(i_first, ) * + i_second / ];
s_ret = s_ret + encmap[mod(i_second, ) * + i_third / ];
s_ret = s_ret + encmap[mod(i_third, )];
i = i + ;
}
if (i < len(a_text))
{
i_first = asc(mid(a_text, i + , ));
if ((a_text.Length % ) == )
{
i_second = asc(mid(a_text, i + , ));
s_ret = s_ret + encmap[i_first / ];
s_ret = s_ret + encmap[mod(i_first, ) * + i_second / ];
s_ret = s_ret + encmap[mod(i_second, ) * ];
s_ret = s_ret + "=";
}
else
{
s_ret = s_ret + encmap[i_first / ];
s_ret = s_ret + encmap[mod(i_first, ) * ];
s_ret = s_ret + "==";
}
}
i_len = len(s_ret);
s_ret = left((i_len + ).ToString(), ) + s_ret;
}
else
{ a_text = right(a_text, len(a_text) - );
reallen = len(a_text);
while (mid(a_text, reallen - , ) == '=')
{
reallen = reallen - ;
} by4 = reallen - mod(reallen, ); i = ; while (i < by4)
{
i_first = decmap[asc(mid(a_text, i + , ))];
i_second = decmap[asc(mid(a_text, i + , ))];
i_third = decmap[asc(mid(a_text, i + , ))];
i_fourth = decmap[asc(mid(a_text, i + , ))];
s_ret = s_ret + (char)(i_first * + i_second / );
s_ret = s_ret + (char)(mod(i_second, ) * + i_third / );
if (mod(i_third, ) * + i_fourth != )
{
s_ret = s_ret + (char)(mod(i_third, ) * + i_fourth);
}
i = i + ;
}
if (i < reallen)
{
//只可能是xx==或xxx=两种形式有效
if (mod(reallen, ) == ) //xx==形式
{
i_first = decmap[asc(mid(a_text, i + , ))];
i_second = decmap[asc(mid(a_text, i + , ))];
s_ret = s_ret + (char)(i_first * + i_second / );
s_ret = s_ret + (char)(mod(i_second, ) * );
}
else
{
i_first = decmap[asc(mid(a_text, i + , ))];
i_second = decmap[asc(mid(a_text, i + , ))];
i_third = decmap[asc(mid(a_text, i + , ))];
s_ret = s_ret + (char)(i_first * + i_second / );
s_ret = s_ret + (char)(mod(i_second, ) * + i_third / );
}
}
}
return s_ret;
}

pb加密转换成C#的更多相关文章

  1. 一个java的DES加密解密类转换成C#

    一个java的des加密解密代码如下: //package com.visionsky.util; import java.security.*; //import java.util.regex.P ...

  2. 生成二维码 加密解密类 TABLE转换成实体、TABLE转换成实体集合(可转换成对象和值类型) COOKIE帮助类 数据类型转换 截取字符串 根据IP获取地点 生成随机字符 UNIX时间转换为DATETIME\DATETIME转换为UNIXTIME 是否包含中文 生成秘钥方式之一 计算某一年 某一周 的起始时间和结束时间

    生成二维码 /// <summary>/// 生成二维码/// </summary>public static class QRcodeUtils{private static ...

  3. h5模型文件转换成pb模型文件

      本文主要记录Keras训练得到的.h5模型文件转换成TensorFlow的.pb文件 #*-coding:utf-8-* """ 将keras的.h5的模型文件,转换 ...

  4. java将office文档pdf文档转换成swf文件在线预览

    第一步,安装openoffice.org openoffice.org是一套sun的开源office办公套件,能在widows,linux,solaris等操作系统上执行. 主要模块有writer(文 ...

  5. https,https的本地测试环境搭建,asp.net结合https的代码实现,http网站转换成https网站之后遇到的问题

    一:什么是https SSL(Security   Socket   Layer)全称是加密套接字协议层,它位于HTTP协议层和TCP协议层之间,用于建立用户与服务器之间的加密通信,确保所传递信息的安 ...

  6. 【转】https,https的本地测试环境搭建,asp.net结合https的代码实现,http网站转换成https网站之后遇到的问题

    正需要这个,写的很好,就转过来了 转自: http://www.cnblogs.com/naniannayue/ 一:什么是https SSL(Security   Socket   Layer)全称 ...

  7. 一个java的DES加解密类转换成C#

    原文:一个java的DES加解密类转换成C# 一个java的des加密解密代码如下: //package com.visionsky.util; import java.security.*; //i ...

  8. Unix时间戳转换成C#中的DateTime

    先交代一下应用场景:我们的软件需要做一个简单的有效期验证保护.初始的想法是 在本地将安装时间.启动时间.当前时间做比较,为了防止记录被修改,记录在注册表的特殊的地方并加密. 我使用了.net自带的rs ...

  9. 【转】qlv文件如何转换成mp4 怎样把下载好的qlv格式视频转换成MP4格式

    狸窝  复制  收藏  保存到桌面  快速找教程方案  反馈需求  社会主义核心价值观  客服QQ41442901   马上注册 升级VIP   对于视频文件之间的转换问题,我也已经是无力吐槽了,每个 ...

随机推荐

  1. vue -- v-model 表单绑定

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. vue组件引入

    /src/route/index.js import Demo2 from '@/pages/demo2/index.vue' { path : '/demo2', name : 'demo2', c ...

  3. Html基本控件介绍

    1. <input>标签<input> 标签用于搜集用户信息. 1.1 type属性根据不同的 type 属性值,输入字段拥有很多种形式.可以是文本字段.复选框.掩码后的文本控 ...

  4. php/js将 CST时间转成格式化时间

    PHP :比较简单 $str = 'Wed Jul 24 11:24:33 CST 2019'; echo date('Y-m-d H:i:s', strtotime($str)); echo dat ...

  5. html代码分享

    贴图:<img src="图片URL"> 加入连接:<a href="所要连接的相关URL">写上你想写的字</a> 在新窗 ...

  6. 新手学习PHP的避雷针,这些坑在PHP开发中就别跳了

    不要!用记事本编辑php文件 早些年能用记事本编程是一些人自我吹嘘的资本,能用记事本编程就是牛逼的代名词.但是这里要告诫大家的是,千万不要使用Windows自带的记事本编辑任何文本文件.用Window ...

  7. nmonchart 分析.nmon监控数据成html展示

    下载地址:http://nmon.sourceforge.net/pmwiki.php?n=Site.Nmonchart chart安装包:http://sourceforge.net/project ...

  8. hdu 6214 Smallest Minimum Cut(最小割的最少边数)

    题目大意是给一张网络,网络可能存在不同边集的最小割,求出拥有最少边集的最小割,最少的边是多少条? 思路:题目很好理解,就是找一个边集最少的最小割,一个方法是在建图的时候把边的容量处理成C *(E+1 ...

  9. opencv:轮廓匹配

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...

  10. 【StarUML】组件图

    架构设计中可视化地表达各个组件之间依赖关系以及组件的接口调用情况 1.元素 a.组件 b.接口 b1.组件暴露接口 暴露接口,需要先画一个接口 然后建立组件和接口的联系,这里是暴露接口,那么这个连线就 ...