Function getHexDec(strHex)
' Function Converts a single hex value into it's decimal equivalent
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Select Case strHex
Case "0"
getHexDec = 0
Case "1"
getHexDec = 1
Case "2"
getHexDec = 2
Case "3"
getHexDec = 3
Case "4"
getHexDec = 4
Case "5"
getHexDec = 5
Case "6"
getHexDec = 6
Case "7"
getHexDec = 7
Case "8"
getHexDec = 8
Case "9"
getHexDec = 9
Case "A"
getHexDec = 10
Case "B"
getHexDec = 11
Case "C"
getHexDec = 12
Case "D"
getHexDec = 13
Case "E"
getHexDec = 14
Case "F"
getHexDec = 15
Case Else
getHexDec = -1
End Select
End Function
Function getDecHex(strHex)
' Function Converts a single decimal value(0 - 15) into it's hex equivalent
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Select Case CInt(strHex)
Case 0
getDecHex = "0"
Case 1
getDecHex = "1"
Case 2
getDecHex = "2"
Case 3
getDecHex = "3"
Case 4
getDecHex = "4"
Case 5
getDecHex = "5"
Case 6
getDecHex = "6"
Case 7
getDecHex = "7"
Case 8
getDecHex = "8"
Case 9
getDecHex = "9"
Case 10
getDecHex = "A"
Case 11
getDecHex = "B"
Case 12
getDecHex = "C"
Case 13
getDecHex = "D"
Case 14
getDecHex = "E"
Case 15
getDecHex = "F"
Case Else
getDecHex = "Z"
End Select
End Function
Function BinaryShift(strBinary, intPos)
' Function circular left shifts a binary value n places
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
BinaryShift = Right(strBinary, Len(strBinary) - cint(intPos)) & _
Left(strBinary, cint(intPos))
End Function
Function BinaryXOR(strBin1, strBin2)
' Function performs an exclusive or function on each position of two binary values
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Dim strBinaryFinal
Dim intPos
For intPos = 1 To Len(strBin1)
Select Case Mid(strBin1, cint(intPos), 1)
Case Mid(strBin2, cint(intPos), 1)
strBinaryFinal = strBinaryFinal & "0"
Case Else
strBinaryFinal = strBinaryFinal & "1"
End Select
Next
BinaryXOR = strBinaryFinal
End Function
Function BinaryOR(strBin1, strBin2)
' Function performs an inclusive or function on each position of two binary values
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Dim strBinaryFinal
Dim intPos
For intPos = 1 To Len(strBin1)
If Mid(strBin1, cint(intPos), 1) = "1" Or Mid(strBin2, cint(intPos), 1) = "1" Then
strBinaryFinal = strBinaryFinal & "1"
Else
strBinaryFinal = strBinaryFinal & "0"
End If
Next
BinaryOR = strBinaryFinal
End Function
Function BinaryAND(strBin1, strBin2)
' Function performs an AND function on each position of two binary values
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Dim strBinaryFinal
Dim intPos
For intPos = 1 To Len(strBin1)
If Mid(strBin1, cint(intPos), 1) = "1" And Mid(strBin2, cint(intPos), 1) = "1" Then
strBinaryFinal = strBinaryFinal & "1"
Else
strBinaryFinal = strBinaryFinal & "0"
End If
Next
BinaryAND = strBinaryFinal
End Function
Function BinaryNOT(strBinary)
' Function makes each position of a binary value from 1 to 0 and 0 to 1
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Dim strBinaryFinal
Dim intPos
For intPos = 1 To Len(strBinary)
If Mid(strBinary, cint(intPos), 1) = "1" Then
strBinaryFinal = strBinaryFinal & "0"
Else
strBinaryFinal = strBinaryFinal & "1"
End If
Next
BinaryNOT = strBinaryFinal
End Function
Function HexBlockToBinary(strHex)
' Function Converts a 8 digit/32 bit hex value to its 32 bit binary equivalent
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Dim intPos
Dim strTemp
For intPos = 1 To Len(strHex)
strTemp = strTemp & HexToBinary(Mid(strHex, cint(intPos), 1))
Next
' Function Converts an integer number to it's binary equivalent
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Dim strBinary, strTemp
Dim intNew, intTemp
Dim dblNew
intNew = intNum
Do While intNew > 1
dblNew = CDbl(intNew) / 2
intNew = Round(CDbl(dblNew) - 0.1, 0)
If CDbl(dblNew) = CDbl(intNew) Then
strBinary = "0" & strBinary
Else
strBinary = "1" & strBinary
End If
Loop
strBinary = intNew & strBinary
intTemp = Len(strBinary) mod 8
For intNew = intTemp To 7
strBinary = "0" & strBinary
Next
IntToBinary = strBinary
End Function
Function PadBinary(strBinary)
' Function adds 0's to a binary string until it reaches 448 bits.
' The lenghth of the original string is incoded into the last 16 bits.
' The end result is a binary string 512 bits long
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Dim intPos, intLen
Dim strTemp
intLen = Len(strBinary)
strBinary = strBinary & "1"
For intPos = Len(strBinary) To 447
strBinary = strBinary & "0"
Next
strTemp = IntToBinary(intLen)
For intPos = Len(strTemp) To 63
strTemp = "0" & strTemp
Next
strBinary = strBinary & strTemp
PadBinary = strBinary
End Function
Function BlockToHex(strBinary)
' Function Converts a 32 bit binary string into it's 8 digit hex equivalent
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Dim intPos
Dim strHex
For intPos = 1 To Len(strBinary) Step 4
strHex = strHex & BinaryToHex(Mid(strBinary, intPos, 4))
Next
BlockToHex = strHex
End Function
Function DigestHex(strHex, strH0, strH1, strH2, strH3, strH4)
' Main encoding function. Takes a 128 digit/512 bit hex value and one way encrypts it into
' a 40 digit/160 bit hex value.
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Dim strWords(79), adoConst(4), strTemp, strTemp1, strTemp2, strTemp3, strTemp4
Dim intPos
Dim strH(4), strA(4), strK(3)
'Constant hex words are used for encryption, these can be any valid 8 digit hex value
strK(0) = "5A827999"
strK(1) = "6ED9EBA1"
strK(2) = "8F1BBCDC"
strK(3) = "CA62C1D6"
'Hex words are used in the encryption process, these can be any valid 8 digit hex value
strH(0) = strH0
strH(1) = strH1
strH(2) = strH2
strH(3) = strH3
strH(4) = strH4
'divide the Hex block into 16 hex words
For intPos = 0 To (len(strHex) / 8) - 1
strWords(cint(intPos)) = Mid(strHex, (cint(intPos)*8) + 1, 8)
Next
'encode the Hex words using the constants above
'innitialize 80 hex word positions
For intPos = 16 To 79
strTemp = strWords(cint(intPos) - 3)
strTemp1 = HexBlockToBinary(strTemp)
strTemp = strWords(cint(intPos) - 8)
strTemp2 = HexBlockToBinary(strTemp)
strTemp = strWords(cint(intPos) - 14)
strTemp3 = HexBlockToBinary(strTemp)
strTemp = strWords(cint(intPos) - 16)
strTemp4 = HexBlockToBinary(strTemp)
strTemp = BinaryXOR(strTemp1, strTemp2)
strTemp = BinaryXOR(strTemp, strTemp3)
strTemp = BinaryXOR(strTemp, strTemp4)
strWords(cint(intPos)) = BlockToHex(BinaryShift(strTemp, 1))
Next
'initialize the changing word variables with the initial word variables
strA(0) = strH(0)
strA(1) = strH(1)
strA(2) = strH(2)
strA(3) = strH(3)
strA(4) = strH(4)
'Main encryption loop on all 80 hex word positions
For intPos = 0 To 79
strTemp = BinaryShift(HexBlockToBinary(strA(0)), 5)
strTemp1 = HexBlockToBinary(strA(3))
strTemp2 = HexBlockToBinary(strWords(cint(intPos)))
'Concatenate the final Hex Digest
DigestHex = strA(0) & strA(1) & strA(2) & strA(3) & strA(4)
End Function
Function HexAdd(strHex1, strHex2)
' Function adds to 8 digit/32 bit hex values together Mod 2^32
'
' Written By: Mark Jager
' Written Date: 8/10/2000
'
' Free to distribute as long as code is not modified, and header is kept intact
'
Dim intCalc
Dim strNew
intCalc = 0
intCalc = CDbl(CDbl(HexToInt(strHex1)) + CDbl(HexToInt(strHex2)))
Do While CDbl(intCalc) > 2^32
intCalc = CDbl(intCalc) - 2^32
Loop
strNew = IntToBinary(CDbl(intCalc))
Do While Len(strNew) < 32
strNew = "0" & strNew
Loop
strNew = BlockToHex(strNew)
if InStr(strNew, "00") = 1 and len(strNew) = 10 then
strNew = right(strNew, 8)
end if