- 浏览: 466377 次
- 性别:
- 来自: 广州
最新评论
-
lhgyy00:
很好,回去好好研究下,3Q
博客资源与博客工具大全 -
ljl.java:
♦
你会遇到几段恋情?很准的哦~ -
ljl.java:
♦
你会遇到几段恋情?很准的哦~ -
jzzwy:
你这个red5是什么版本 Iterator<IConne ...
red5获取在线用户列表 -
81365341:
看着标题“red5配置详解”点进来的,结果没看到一句和配置有关 ...
red5配置详解
前些日子不少人都要挂QQ,有客户需求就自然有人去研究,所以不少人开始研究QQ的协议.其中最重要的一步就是研究QQ使用的加密算法---TEA算法
关于TEA算法的描述以及C语言源码这里就不多说了,现在给出该算法的VB实现
' ----------------------------------------------------------------------------------
' | |
' | 标准TEA加密解密模块 |
' | |
' ----------------------------------------------------------------------------------
Private Const OFFSET_4 = 4294967296# '&h100000000 的数值
Private Const MAXINT_4 = 2147483647 '整型数据所能表示的最大正数值 (&h7fffffff)
Private Const Bit_32 = 2147483648# '&h80000000 的正整数形式
Private Const DELTA = &H9E3779B9 'TEA算法的DELTA值
Private Function AddLong(lX As Long, lY As Long) As Long '长整数加法函数
Dim lX4 As Long
Dim lY4 As Long
Dim lX8 As Long
Dim lY8 As Long
Dim lResult As Long
lX8 = lX And &H80000000
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000
lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
If lX4 And lY4 Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf lX4 Or lY4 Then
If lResult And &H40000000 Then
lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
Else
lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
End If
Else
lResult = lResult Xor lX8 Xor lY8
End If
AddLong = lResult
End Function
Private Function SubtractLong(lX As Long, lY As Long) As Long '长整数减法函数
Dim lX8 As Long
Dim lY8 As Long
Dim mX As Double
Dim mY As Double
Dim mResult As Double
Dim lResult As Long
lX8 = lX And &H80000000
lY8 = lY And &H80000000
mX = lX And &H7FFFFFFF
mY = lY And &H7FFFFFFF
If lX8 Then
If lY8 Then
mResult = mX - mY
Else
mX = mX + Bit_32
mResult = mX - mY
End If
Else
If lY8 Then
mY = lY
mResult = mX - mY
Else
mResult = mX - mY
End If
End If
If mResult < 0 Then
lResult = ((Bit_32 + mResult) Or &H80000000) And &HFFFFFFFF
ElseIf mResult > MAXINT_4 Then
lResult = ((mResult - Bit_32) Or &H80000000) And &HFFFFFFFF
Else
lResult = mResult And &HFFFFFFFF
End If
SubtractLong = lResult
End Function
Private Function LeftRotateLong(lValue As Long, lBits As Integer) As Long '按位左移函数
Dim lngSign As Long, intI As Integer
Dim mValue As Long
lBits = lBits Mod 32
mValue = lValue
If lBits = 0 Then LeftRotateLong = mValue: Exit Function
For intI = 1 To lBits
lngSign = mValue And &H40000000
mValue = (mValue And &H3FFFFFFF) * 2
If lngSign And &H40000000 Then
mValue = mValue Or &H80000000
End If
Next
LeftRotateLong = mValue
End Function
Private Function RightRotateLong(lValue As Long, lBits As Integer) As Long '按位右移函数
Dim lngSign As Long, intI As Integer
Dim mValue As Long
mValue = lValue
lBits = lBits Mod 32
If lBits = 0 Then RightRotateLong = mValue: Exit Function
For intI = 1 To lBits
lngSign = mValue And &H80000000
mValue = (mValue And &H7FFFFFFF) \ 2
If lngSign Then
mValue = mValue Or &H40000000
End If
Next
RightRotateLong = mValue
End Function
Public Sub TeaEncode(v() As Long, k() As Long, lType As Integer) '标准的TEA加密过程,参数lType 为1时表示16轮迭代(QQ使用的就是16轮迭代),否则为32轮迭代
Dim Y As Long, Z As Long
Dim K1 As Long, K2 As Long, K3 As Long, K4 As Long
Dim L1 As Long, L2 As Long, L3 As Long, L4 As Long
Dim Sum As Long
Dim i As Integer, Rounds As Integer
Dim mResult(0 To 1) As Long
Y = v(0)
Z = v(1)
K1 = k(0)
K2 = k(1)
K3 = k(2)
K4 = k(3)
If lType = 1 Then
Rounds = 16
Else
Rounds = 32
End If
For i = 1 To Rounds
'sum += delta ;
Sum = AddLong(Sum, DELTA)
'y += (z<<4)+k[0] ^ z+sum ^ (z>>5)+k[1]
L1 = LeftRotateLong(Z, 4)
L1 = AddLong(L1, K1)
L2 = AddLong(Z, Sum)
L3 = RightRotateLong(Z, 5)
L3 = AddLong(L3, K2)
L4 = L1 Xor L2 Xor L3
Y = AddLong(Y, L4)
'z += (y<<4)+k[2] ^ y+sum ^ (y>>5)+k[3]
L1 = LeftRotateLong(Y, 4)
L1 = AddLong(L1, K3)
L2 = AddLong(Y, Sum)
L3 = RightRotateLong(Y, 5)
L3 = AddLong(L3, K4)
L4 = L1 Xor L2 Xor L3
Z = AddLong(Z, L4)
Next
v(0) = Y
v(1) = Z
End Sub
Public Sub TeaDecode(v() As Long, k() As Long, lType As Integer) '标准TEA解密过程,参数lType 为1时表示16轮迭代(QQ使用的就是16轮迭代),否则为32轮迭代
Dim Y As Long, Z As Long
Dim K1 As Long, K2 As Long, K3 As Long, K4 As Long
Dim L1 As Long, L2 As Long, L3 As Long, L4 As Long
Dim Sum As Long
Dim i As Integer, Rounds As Integer
Dim mResult(0 To 1) As Long
Y = v(0)
Z = v(1)
K1 = k(0)
K2 = k(1)
K3 = k(2)
K4 = k(3)
If lType = 1 Then
Rounds = 16
Sum = LeftRotateLong(DELTA, 4)
Else
Rounds = 32
Sum = LeftRotateLong(DELTA, 5)
End If
For i = 1 To Rounds
L1 = LeftRotateLong(Y, 4)
L1 = AddLong(L1, K3)
L2 = AddLong(Y, Sum)
L3 = RightRotateLong(Y, 5)
L3 = AddLong(L3, K4)
L4 = L1 Xor L2 Xor L3
Z = SubtractLong(Z, L4)
L1 = LeftRotateLong(Z, 4)
L1 = AddLong(L1, K1)
L2 = AddLong(Z, Sum)
L3 = RightRotateLong(Z, 5)
L3 = AddLong(L3, K2)
L4 = L1 Xor L2 Xor L3
Y = SubtractLong(Y, L4)
Sum = SubtractLong(Sum, DELTA)
Next
v(0) = Y
v(1) = Z
End Sub
关于TEA算法的描述以及C语言源码这里就不多说了,现在给出该算法的VB实现
' ----------------------------------------------------------------------------------
' | |
' | 标准TEA加密解密模块 |
' | |
' ----------------------------------------------------------------------------------
Private Const OFFSET_4 = 4294967296# '&h100000000 的数值
Private Const MAXINT_4 = 2147483647 '整型数据所能表示的最大正数值 (&h7fffffff)
Private Const Bit_32 = 2147483648# '&h80000000 的正整数形式
Private Const DELTA = &H9E3779B9 'TEA算法的DELTA值
Private Function AddLong(lX As Long, lY As Long) As Long '长整数加法函数
Dim lX4 As Long
Dim lY4 As Long
Dim lX8 As Long
Dim lY8 As Long
Dim lResult As Long
lX8 = lX And &H80000000
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000
lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
If lX4 And lY4 Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf lX4 Or lY4 Then
If lResult And &H40000000 Then
lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
Else
lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
End If
Else
lResult = lResult Xor lX8 Xor lY8
End If
AddLong = lResult
End Function
Private Function SubtractLong(lX As Long, lY As Long) As Long '长整数减法函数
Dim lX8 As Long
Dim lY8 As Long
Dim mX As Double
Dim mY As Double
Dim mResult As Double
Dim lResult As Long
lX8 = lX And &H80000000
lY8 = lY And &H80000000
mX = lX And &H7FFFFFFF
mY = lY And &H7FFFFFFF
If lX8 Then
If lY8 Then
mResult = mX - mY
Else
mX = mX + Bit_32
mResult = mX - mY
End If
Else
If lY8 Then
mY = lY
mResult = mX - mY
Else
mResult = mX - mY
End If
End If
If mResult < 0 Then
lResult = ((Bit_32 + mResult) Or &H80000000) And &HFFFFFFFF
ElseIf mResult > MAXINT_4 Then
lResult = ((mResult - Bit_32) Or &H80000000) And &HFFFFFFFF
Else
lResult = mResult And &HFFFFFFFF
End If
SubtractLong = lResult
End Function
Private Function LeftRotateLong(lValue As Long, lBits As Integer) As Long '按位左移函数
Dim lngSign As Long, intI As Integer
Dim mValue As Long
lBits = lBits Mod 32
mValue = lValue
If lBits = 0 Then LeftRotateLong = mValue: Exit Function
For intI = 1 To lBits
lngSign = mValue And &H40000000
mValue = (mValue And &H3FFFFFFF) * 2
If lngSign And &H40000000 Then
mValue = mValue Or &H80000000
End If
Next
LeftRotateLong = mValue
End Function
Private Function RightRotateLong(lValue As Long, lBits As Integer) As Long '按位右移函数
Dim lngSign As Long, intI As Integer
Dim mValue As Long
mValue = lValue
lBits = lBits Mod 32
If lBits = 0 Then RightRotateLong = mValue: Exit Function
For intI = 1 To lBits
lngSign = mValue And &H80000000
mValue = (mValue And &H7FFFFFFF) \ 2
If lngSign Then
mValue = mValue Or &H40000000
End If
Next
RightRotateLong = mValue
End Function
Public Sub TeaEncode(v() As Long, k() As Long, lType As Integer) '标准的TEA加密过程,参数lType 为1时表示16轮迭代(QQ使用的就是16轮迭代),否则为32轮迭代
Dim Y As Long, Z As Long
Dim K1 As Long, K2 As Long, K3 As Long, K4 As Long
Dim L1 As Long, L2 As Long, L3 As Long, L4 As Long
Dim Sum As Long
Dim i As Integer, Rounds As Integer
Dim mResult(0 To 1) As Long
Y = v(0)
Z = v(1)
K1 = k(0)
K2 = k(1)
K3 = k(2)
K4 = k(3)
If lType = 1 Then
Rounds = 16
Else
Rounds = 32
End If
For i = 1 To Rounds
'sum += delta ;
Sum = AddLong(Sum, DELTA)
'y += (z<<4)+k[0] ^ z+sum ^ (z>>5)+k[1]
L1 = LeftRotateLong(Z, 4)
L1 = AddLong(L1, K1)
L2 = AddLong(Z, Sum)
L3 = RightRotateLong(Z, 5)
L3 = AddLong(L3, K2)
L4 = L1 Xor L2 Xor L3
Y = AddLong(Y, L4)
'z += (y<<4)+k[2] ^ y+sum ^ (y>>5)+k[3]
L1 = LeftRotateLong(Y, 4)
L1 = AddLong(L1, K3)
L2 = AddLong(Y, Sum)
L3 = RightRotateLong(Y, 5)
L3 = AddLong(L3, K4)
L4 = L1 Xor L2 Xor L3
Z = AddLong(Z, L4)
Next
v(0) = Y
v(1) = Z
End Sub
Public Sub TeaDecode(v() As Long, k() As Long, lType As Integer) '标准TEA解密过程,参数lType 为1时表示16轮迭代(QQ使用的就是16轮迭代),否则为32轮迭代
Dim Y As Long, Z As Long
Dim K1 As Long, K2 As Long, K3 As Long, K4 As Long
Dim L1 As Long, L2 As Long, L3 As Long, L4 As Long
Dim Sum As Long
Dim i As Integer, Rounds As Integer
Dim mResult(0 To 1) As Long
Y = v(0)
Z = v(1)
K1 = k(0)
K2 = k(1)
K3 = k(2)
K4 = k(3)
If lType = 1 Then
Rounds = 16
Sum = LeftRotateLong(DELTA, 4)
Else
Rounds = 32
Sum = LeftRotateLong(DELTA, 5)
End If
For i = 1 To Rounds
L1 = LeftRotateLong(Y, 4)
L1 = AddLong(L1, K3)
L2 = AddLong(Y, Sum)
L3 = RightRotateLong(Y, 5)
L3 = AddLong(L3, K4)
L4 = L1 Xor L2 Xor L3
Z = SubtractLong(Z, L4)
L1 = LeftRotateLong(Z, 4)
L1 = AddLong(L1, K1)
L2 = AddLong(Z, Sum)
L3 = RightRotateLong(Z, 5)
L3 = AddLong(L3, K2)
L4 = L1 Xor L2 Xor L3
Y = SubtractLong(Y, L4)
Sum = SubtractLong(Sum, DELTA)
Next
v(0) = Y
v(1) = Z
End Sub
发表评论
-
TEA算法的VB实现代码的使用说明
2008-12-30 11:28 1948自从公开了TEA算法的VB代码之后一直有人追问我如何调用这两个 ... -
QQ通讯协议
2008-12-30 10:56 4208协议说明: 协议由报文 ... -
hoxede的QQ填充算法和TEA 加解密的python实现
2008-12-30 10:31 2919""" The MIT Lic ... -
如何从 Visual Basic 中调用 GetNetworkParams / GetAdapter
2008-12-30 09:52 17331. 启动一个新的 Visual Basic 标准 EX ... -
VB调用GetAdaptersInfo 的正确方法
2008-12-30 09:51 2746网上的教程没有一个能在多网卡或多IP下用的,总是在 Cop ... -
VB做的EXE文件设参数
2008-12-29 12:26 1227这个其实很简单 在 Private Sub Form_L ... -
VB常用字符串函数
2008-12-29 12:26 15021. ASC(X),Chr(X):转换字 ... -
VB常用函数
2008-12-29 12:25 23301. Time 返回系统时钟的当前时间。 Date 返回 ... -
VB使用*.res资源文件
2008-12-29 12:23 1695你一定也常常因苦于无法组织自己程序中大量的picture,而头 ... -
在不同的模式下实现定时关闭计算机
2008-12-29 12:20 888Option Explicit Const SM_CLEANB ... -
强制关闭指定QQ号
2008-12-29 12:19 1345'添加 Text1 Command1 ... -
VB读取武林外传内存地址
2008-12-29 12:18 2122一 模块代码 复制内容到剪贴板 代码: Option Expl ... -
怎么编程把用户名,密码提交到网页上的登录页?
2008-12-29 12:06 1477首先在程序中加入Webbrowser控件并加入引用 Micro ... -
在XP/2K 任务管理器的进程列表中隐藏当前进程
2008-12-29 12:05 1273新建一个模块,把以下代码复制进去,然后在load中调用即可实现 ... -
用VB制作IE工具条自定义按钮
2008-12-29 12:04 1215Private Sub UserControl_Resize( ... -
Webbrowser(Internet 控件)属性方法事件一览表
2008-12-29 11:56 4828想找个Webbrowser控件的详细使用手册,网上找了好久,都 ... -
使用vbs下载文件
2008-12-29 11:52 1573使用vbs下载文件 iLocal=LCase(Wscript. ... -
如何用VB制作半透明窗体?
2008-12-29 11:51 1720函数SetLayeredWindowAttributes ... -
vb api 控制 任务栏 桌面 托盘。。
2008-12-29 11:45 2114VB无疑是最先进的编程 ... -
VB程序实现文件拖放功能
2008-12-26 10:25 16261.新建一个模块,写入以 ...
相关推荐
使用VB实现TEA算法时,需要注意的是VB的整数类型可能只有16位,因此可能需要使用Long类型来存储32位的数值。此外,为了防止溢出,你需要在计算过程中特别小心。 在程序注册保护中,TEA算法可以用来加密用户的注册...
`TEA.cls`文件可能包含了VB中的TEA算法实现,用于快速加密和解密小数据块。 9. **Twofish**: Twofish是Blowfish的后继者,设计更加强大且安全。`clsTwofish.cls`文件可能包含了VB实现的Twofish算法,支持更长的...
这些VB6加密类模块为开发者提供了实现各种加密算法的基础,可以根据实际需求选择合适的算法来保护数据。不过,值得注意的是,随着技术的发展,新的加密标准和更安全的算法不断出现,如AES,开发者应持续关注最新的...
这个加解密源码几乎包括了世界上几个最著名的加密算法:Blowfish、CryptAPI、DES、Gost、RC4、XOR、Skipjack、TEA、Twofish,曾获源码5星推荐 Business-strengthCompression.zip: 商用压缩+加密程序 ...
在VB(Visual Basic)编程环境中,这些加密算法可以被用于创建安全的应用程序,例如实现数据加密、解密功能。源码的提供使得开发者能够理解和学习这些算法的实现细节,从而提高他们的编程技能和安全意识。在下载并...
VB 6.0 Blowfish、CryptAPI、DES、Gost、RC4、XOR等加密算法集,这个加解密源码几乎包括了世界上几个最著名的加密算法:Blowfish、CryptAPI、DES、Gost、RC4、XOR、Skipjack、TEA、Twofish,曾获源码5星推荐。...
标准算法模块是集DES、3DES、AES、RSA、MD5、BlowFish、TEA、RC6等标准算法为一体的算法包,同时在模块中使用了Anti-Debug和程序自校验功能(涉及到软件的加壳和CRC32)、软件使用次数限制,更好的保护您的软件。...
这个加解密源码几乎包括了世界上几个最著名的加密算法:Blowfish、CryptAPI、DES、Gost、RC4、XOR、Skipjack、TEA、Twofish,曾获源码5星推荐 Business-strengthCompression.zip: 商用压缩+加密程序 ...
标准算法模块是集DES、3DES、AES、RSA、MD5、BlowFish、TEA、RC6等标准算法为一体的算法包,同时在模块中使用了Anti-Debug和程序自校验功能(涉及到软件的加壳和CRC32)、软件使用次数限制,更好的保护您的软件。...
摘要:VB源码,算法相关,Crypto VBCrypto源码库大全源码,这是一个良好的编译算法,由如下算法组成:10种流行的加密算法(Blowfish, Twofish, Rijndael, Skipjack, Serpent, Gost, RC2, RC4, TEA, DES, 3DES, 3DES...
本文将深入探讨VB(Visual Basic)编程环境中涉及的多种加密算法,包括DES、RC4、TEA等,并介绍它们的基本原理、应用以及在VB中的实现。 首先,DES(Data Encryption Standard)是一种古老的对称加密算法,由IBM...
通过这些文件,开发者可以深入理解TeaAsm的工作原理,学习如何在VB中操作汇编代码以及实现加密算法。对于学习编程和提高技能的开发者来说,这是一个宝贵的资源,尤其是对汇编语言和加密算法感兴趣的人员。同时,开源...
标准算法模块是集DES、3DES、AES、RSA、MD5、BlowFish、TEA、RC6等标准算法为一体的算法包,同时在模块中使用了Anti-Debug和程序自校验功能(涉及到软件的加壳和CRC32)、软件使用次数限制,更好的保护您的软件。...
标准算法模块是集DES、3DES、AES、RSA、MD5、BlowFish、TEA、RC6等标准算法为一体的算法包,同时在模块中使用了Anti-Debug和程序自校验功能(涉及到软件的加壳和CRC32)、软件使用次数限制,更好的保护您的软件。...
标准算法模块是集DES、3DES、AES、RSA、MD5、BlowFish、TEA、RC6等标准算法为一体的算法包,同时在模块中使用了Anti-Debug和程序自校验功能(涉及到软件的加壳和CRC32)、软件使用次数限制,更好的保护您的软件。...
在VB编程中,首先需要分析问题,确定解决问题的算法,然后在编程环境中设计界面并编写代码,最后是调试和运行程序。正确的顺序是:分析问题 -> 设计界面和编写代码 -> 调试运行。 3. **算法输入与输出**:算法的...