CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

求vb中的加密函数及其算法

楼主newslxw(lxw)2003-11-02 09:53:56 在 VB / 基础类 提问

求vb中的加密函数及其算法 问题点数:20、回复次数:5Top

1 楼itlive(好友(暂别VB版))回复于 2003-11-02 10:38:39 得分 0

不明白你是什么意思说详细点Top

2 楼newslxw(lxw)回复于 2003-11-02 10:55:34 得分 0

vb中有一个函数是把用户的密码加密的,Top

3 楼mingtian2008(明天)回复于 2003-11-02 11:00:23 得分 0

upTop

4 楼blueice2002(蓝冰)回复于 2003-11-26 17:41:35 得分 20

Option   Explicit  
   
  '   Encipher   the   text   using   the   pasword.  
  '加密  
  Private   Sub   Cipher(ByVal   password   As   String,   ByVal   from_text   As   String,   to_text   As   String)  
  Const   MIN_ASC   =   32     '   Space.  
  Const   MAX_ASC   =   126   '   ~.  
  Const   NUM_ASC   =   MAX_ASC   -   MIN_ASC   +   1  
   
  Dim   offset   As   Long  
  Dim   str_len   As   Integer  
  Dim   i   As   Integer  
  Dim   ch   As   Integer  
   
          '   Initialize   the   random   number   generator.  
          offset   =   NumericPassword(password)  
          Rnd   -1  
          Randomize   offset  
   
          '   Encipher   the   string.  
          str_len   =   Len(from_text)  
          For   i   =   1   To   str_len  
                  ch   =   Asc(Mid$(from_text,   i,   1))  
                  If   ch   >=   MIN_ASC   And   ch   <=   MAX_ASC   Then  
                          ch   =   ch   -   MIN_ASC  
                          offset   =   Int((NUM_ASC   +   1)   *   Rnd)  
                          ch   =   ((ch   +   offset)   Mod   NUM_ASC)  
                          ch   =   ch   +   MIN_ASC  
                          to_text   =   to_text   &   Chr$(ch)  
                  End   If  
          Next   i  
  End   Sub  
  '   Encipher   the   text   using   the   pasword.  
  '解密  
  Private   Sub   Decipher(ByVal   password   As   String,   ByVal   from_text   As   String,   to_text   As   String)  
  Const   MIN_ASC   =   32     '   Space.  
  Const   MAX_ASC   =   126   '   ~.  
  Const   NUM_ASC   =   MAX_ASC   -   MIN_ASC   +   1  
   
  Dim   offset   As   Long  
  Dim   str_len   As   Integer  
  Dim   i   As   Integer  
  Dim   ch   As   Integer  
   
          '   Initialize   the   random   number   generator.  
          offset   =   NumericPassword(password)  
          Rnd   -1  
          Randomize   offset  
   
          '   Encipher   the   string.  
          str_len   =   Len(from_text)  
          For   i   =   1   To   str_len  
                  ch   =   Asc(Mid$(from_text,   i,   1))  
                  If   ch   >=   MIN_ASC   And   ch   <=   MAX_ASC   Then  
                          ch   =   ch   -   MIN_ASC  
                          offset   =   Int((NUM_ASC   +   1)   *   Rnd)  
                          ch   =   ((ch   -   offset)   Mod   NUM_ASC)  
                          If   ch   <   0   Then   ch   =   ch   +   NUM_ASC  
                          ch   =   ch   +   MIN_ASC  
                          to_text   =   to_text   &   Chr$(ch)  
                  End   If  
          Next   i  
  End   Sub  
   
   
  '   Translate   a   password   into   an   offset   value.  
  Private   Function   NumericPassword(ByVal   password   As   String)   As   Long  
  Dim   value   As   Long  
  Dim   ch   As   Long  
  Dim   shift1   As   Long  
  Dim   shift2   As   Long  
  Dim   i   As   Integer  
  Dim   str_len   As   Integer  
   
          str_len   =   Len(password)  
          For   i   =   1   To   str_len  
                  '   Add   the   next   letter.  
                  ch   =   Asc(Mid$(password,   i,   1))  
                  value   =   value   Xor   (ch   *   2   ^   shift1)  
                  value   =   value   Xor   (ch   *   2   ^   shift2)  
   
                  '   Change   the   shift   offsets.  
                  shift1   =   (shift1   +   7)   Mod   19  
                  Debug.Print   shift1  
                  shift2   =   (shift2   +   13)   Mod   23  
                  Debug.Print   shift2  
          Next   i  
          NumericPassword   =   value  
  End   Function  
   
  Private   Sub   cmdCipher_Click()  
  Dim   cipher_text   As   String  
          Cipher   txtPassword.Text,   txtPlain.Text,   cipher_text  
          txtCipher.Text   =   cipher_text  
          txtPlain.Text   =   ""  
  End   Sub  
   
  Private   Sub   cmdDecipher_Click()  
  Dim   plain_text   As   String  
  Dim   cipher_text   As   String  
          Decipher   txtPassword.Text,   txtCipher.Text,   plain_text  
          txtPlain.Text   =   plain_text  
          txtCipher.Text   =   ""  
  End   Sub  
   
  Private   Sub   Form_Load()  
   
  txtPassword.Text   =   Asc("c")  
  End   Sub  
   
  Private   Sub   txtPassword_Change()  
          If   Len(txtPassword.Text)   >   0   Then  
                  cmdCipher.Enabled   =   True  
                  cmdDecipher.Enabled   =   True  
          Else  
                  cmdCipher.Enabled   =   False  
                  cmdDecipher.Enabled   =   False  
          End   If  
  End   Sub  
   
  原理:采用十进制逆进制方法将当前数据转换为十进制数据,然后逐位左移,再然后转换为ASCII码.  
  再进行正序转换.Top

5 楼agamem(O-Money)回复于 2003-11-26 17:53:04 得分 0

到文档中心找Top

相关问题

  • win api里面有没有可以vb中调用的加密/解密的函数?比如des算法的?
  • 谁知道:MD5加密算法在VC里或API有没有函数?
  • 求一段C++写的DES加密算法的函数或者类
  • 急问stl中有哈希算法的函数吗?就是数据加密的
  • 加密算法!
  • vb写的des加密解密的函数调用问题
  • 求加密函数
  • 有没有哪位仁兄手头有加密算法的,提供几个,只要加密函数即可(对字符串进行加密)
  • 请问能不能在vb.net的windows窗体下调用javacript的加密算法escape()函数??
  • 求助:急需一个VB的加密算法

关键词

  • 加密
  • asc
  • ch
  • enabled
  • min
  • len
  • offset
  • const
  • str
  • text

得分解答快速导航

  • 帖主:newslxw
  • blueice2002

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo