如果是Unicode文件,比如中文,那是很方便的,把第一个字节进行处理就能扰乱视线;如果是Anis的话,比较笨的办法是逐字节来做,但是一般密度可以不必这么大,你可以按一定规律异或一下,再异或回来即可
解决方案 »
- 我想问一下VB中关于adodc控件的问题
- 三个月没来了,上来向大家打个问个好。散分~~~~
- 我在DBgrid中输入数据,当切换列时产生错误“多步操作产生错误。请检查每一步的状态值。”,不知是什么原因?,推断是输入数据长度过大,
- 系统数据的导入与导出如何实现(各个系统之间的数据库可能不同,SQL Server 或 Access)
- 十进制和十六进制的转换
- 自定义控件 - 怎样在 IDE 中调用原来的属性页以及暴露象 ComboBox 的 Style 属性?
- 请问读取磁盘序列号的API是哪个?
- 问一个sqlserver里的sql语句问题
- 请问下边的代码为什么不能下载文件?
- 有个问题!!就是如果我用235587697/3 得到一个数,但是,这是一个有很多位的小数,我该如何得到一个保留小数点后两位的数????
- 关于activebar 2.0 问题!
- 在线等待->在VB中怎样得到当前.......
Dim Buff() as ByteOpen "d:\xyf.ttt" For Binary Access Read As #1
ReDim Buff(267)Do While Not EOF(1)
Get #1, , Buff '每次读268个byte进来
'Call 处理Buff 的Routine
Loop
Close #1'以下是写入Binary file的程式
Dim Buff() As Byte
Open "c:\xyf" For Binary Access Write As #1
ReDim Buff(10)
Buff = StrConv("这是一个11", vbFromUnicode)
Put #1, , BuffReDim Buff(1)
Buff(0) = 210
Buff(1) = 70
Put #1, , Buff
Close #1
End Sub
'用XOR可以进行简单的加密
Private m_KeyLen As Long
Private m_KeyValue As StringEvent Progress(Percent As Long)Public Sub EncryptFile(SourceFile As String, DestFile As String, Optional Key As String) Dim Filenr As Integer
Dim ByteArray() As Byte
'Make sure the source file do exist
If (Not FileExist(SourceFile)) Then
Call Err.Raise(vbObjectError, , "Error in Skipjack EncryptFile procedure (Source file does not exist).")
Exit Sub
End If
'Open the source file and read the content
'into a bytearray to pass onto encryption
Filenr = FreeFile
Open SourceFile For Binary As #Filenr
ReDim ByteArray(0 To LOF(Filenr) - 1)
Get #Filenr, , ByteArray()
Close #Filenr
'Encrypt the bytearray
Call EncryptByte(ByteArray(), Key) 'If the destination file already exist we need
'to delete it since opening it for binary use
'will preserve it if it already exist
If (FileExist(DestFile)) Then Kill DestFile
'Store the encrypted data in the destination file
Filenr = FreeFile
Open DestFile For Binary As #Filenr
Put #Filenr, , ByteArray()
Close #FilenrEnd Sub
Public Sub DecryptFile(SourceFile As String, DestFile As String, Optional Key As String) Dim Filenr As Integer
Dim ByteArray() As Byte
'Make sure the source file do exist
If (Not FileExist(SourceFile)) Then
Call Err.Raise(vbObjectError, , "Error in Skipjack EncryptFile procedure (Source file does not exist).")
Exit Sub
End If
'Open the source file and read the content
'into a bytearray to decrypt
Filenr = FreeFile
Open SourceFile For Binary As #Filenr
ReDim ByteArray(0 To LOF(Filenr) - 1)
Get #Filenr, , ByteArray()
Close #Filenr
'Decrypt the bytearray
Call DecryptByte(ByteArray(), Key) 'If the destination file already exist we need
'to delete it since opening it for binary use
'will preserve it if it already exist
If (FileExist(DestFile)) Then Kill DestFile 'Store the decrypted data in the destination file
Filenr = FreeFile
Open DestFile For Binary As #Filenr
Put #Filenr, , ByteArray()
Close #FilenrEnd SubPublic Sub DecryptByte(ByteArray() As Byte, Optional Key As String) 'The same routine is used for encryption
'as well as decryption so why not reuse
'some code and make this class smaller
'(that is if it wasn't for all those damn
'comments ;))
Call EncryptByte(ByteArray(), Key)
End Sub
Public Sub EncryptByte(ByteArray() As Byte, Optional Key As String) Dim Offset As Long
Dim ByteLen As Long
Dim ResultLen As Long
Dim CurrPercent As Long
Dim NextPercent As Long
'Set the new key if one was provided
If (Len(Key) > 0) Then Me.Key = Key
'Get the size of the source array
ByteLen = UBound(ByteArray) + 1
ResultLen = ByteLen
'Loop thru the data encrypting it with
'simply XOR磇ng with the key
For Offset = 0 To (ByteLen - 1)
ByteArray(Offset) = ByteArray(Offset) Xor m_Key(Offset Mod m_KeyLen)
'Update the progress if neccessary
If (Offset >= NextPercent) Then
CurrPercent = Int((Offset / ResultLen) * 100)
NextPercent = (ResultLen * ((CurrPercent + 1) / 100)) + 1
RaiseEvent Progress(CurrPercent)
End If
Next
'Make sure we return a 100% progress
If (CurrPercent <> 100) Then RaiseEvent Progress(100)End Sub
Public Function EncryptString(Text As String, Optional Key As String) As String Dim a As Long
Dim ByteLen As Long
Dim ByteArray() As Byte
'Convert the source string into a byte array
ByteArray() = StrConv(Text, vbFromUnicode)
'Encrypt the byte array
Call EncryptByte(ByteArray(), Key)
'Return the encrypted data as a string
EncryptString = StrConv(ByteArray(), vbUnicode)
End Function
Public Function DecryptString(Text As String, Optional Key As String) As String Dim a As Long
Dim ByteLen As Long
Dim ByteArray() As Byte
'Convert the source string into a byte array
ByteArray() = StrConv(Text, vbFromUnicode)
'Encrypt the byte array
Call DecryptByte(ByteArray(), Key)
'Return the encrypted data as a string
DecryptString = StrConv(ByteArray(), vbUnicode)
End FunctionPublic Property Let Key(New_Value As String) 'Do nothing if the key is buffered
If (m_KeyValue = New_Value) Then Exit Property
'Set the new key and convert it to a
'byte array for faster accessing later
m_KeyValue = New_Value
m_KeyLen = Len(New_Value)
m_Key() = StrConv(m_KeyValue, vbFromUnicode)
End Property